import java.sql.*; /* * This is a simple JDBC client that connects to the MGI ADHOC Database server. * You must first edit this file, and update it with your own username/password. * After you have done this, compile and run this code. * If everything runs correctly, you will get a list of Accession ID's printed out to your screen. * If it does not run properly you will get a stack trace detailing what is going wrong. * Please note that you must have the JConnect jar in your classpath for this snippet to work. * Postgresql JDBC drivers are available from https://jdbc.postgresql.org/download.html */ public class MGIConnect { public static void main(String[] args) { Connection connection = null; // Put your username/password here String username = "username"; String password = "password"; try { // Load the Postgres JDBC driver String driverName = "org.postgresql.Driver"; Class.forName(driverName); // Create a connection to the database String url = "jdbc:postgresql://mgi-adhoc.jax.org:5432/mgd; // Create a new connection to MGI connection = DriverManager.getConnection(url, username, password); // Set up an example query String query = "Select symbol from MRK_MARKER " + "where _Marker_key < 100"; // Create a JDBC Statement java.sql.Statement stmt = connection.createStatement(); // Pass the query through the statement, and get a result set // containing data. ResultSet rs = stmt.executeQuery(query); // Goto the first record of the result set. rs.next(); // Walk through the result set, printing out the accession ID // of the records we brought back. while (!rs.isAfterLast()) { System.out.println(rs.getString("symbol")); rs.next(); } // Close the connection to MGI. connection.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } }