Skip to content

Instantly share code, notes, and snippets.

@ChristianCooper
Created August 25, 2012 15:01
Show Gist options
  • Save ChristianCooper/3466784 to your computer and use it in GitHub Desktop.
Save ChristianCooper/3466784 to your computer and use it in GitHub Desktop.
Example for connecting to schemaverse using Java
import java.sql.*;
/**
* Example Java Schemaverse connection, query and close.
* Assumes that you have org.postgresql.Driver on your path
*/
public class SchemaverseExample {
public static void main(String[] args) throws Exception {
// Force a load of the JDBC driver into the Driver manager
Class.forName("org.postgresql.Driver");
// Open a connection to the database
Connection conn = DriverManager.getConnection("jdbc:postgresql://db.schemaverse.com/schemaverse", "<Your User Name>", "<Your Password>");
// Create a query, execute it, and get the first row of results
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT username, balance, fuel_reserve FROM my_player");
rs.next();
// Print out what we retrieved
System.out.println("username = " + rs.getString("username") + ", balance = " + rs.getInt("balance") + ", fuel_reserve = " + rs.getInt("fuel_reserve"));
// Clean up before we exit
rs.close();
statement.close();
conn.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment