ESP JDBC Driver

Using Aleri's PostgreSQL JDBC driver, you were able to create an application to connect to the SQL Query port and perform queries on a model. In order to do so after migration, you must now perform additional steps to retrieve and use the ESP JDBC driver.

To use the ESP JDBC driver, you must connect to a cluster, retrieve a session ID from ESP, and use it as the argument for the JDBC user connection parameter. The code sample below demonstrates this procedure.

// Create a URI and credentials to connect to the cluster.
Uri serverURI = new Uri.Builder("esp://nstackxp2:9786/default/csv_poll_test").create();
Credentials creds = new Credentials.Builder(Credentials.Type.NONE).create();

System.out.println(serverURI);

// Connect to the cluster
Project project = s_sdk.getProject(serverURI, creds);
project.connect(WAIT_TIME_60000_MS);

// Get the session ID after connecting.
String theSessionID = SDK.getSessionId(serverURI, creds);
System.out.println("The Session ID: " + theSessionID);

// Query the cluster for the project host and port.
Deployment dep = project.getCurrentDeployment();
int sqlPort = dep.getSqlPort();
String host = dep.getHost();
System.out.println("SqlPort = " + sqlPort);

//Server server = s_sdk.getServer(serverURI , creds);
//server.connect();

Jdbc3SimpleDataSource source = new Jdbc3SimpleDataSource();
source.setServerName("localhost");
source.setDatabaseName("database");
source.setUser(theSessionID);
source.setPassword("");
source.setPortNumber(sqlPort);

Connection con = null;
try {
	con = source.getConnection();
	// Use the connection.
} catch (SQLException e) {
	// Log any errors.
}