JDBC Driver for SQL/MP 3.0

Standard Driver Example
In a Java program, this code uses the standard driver, sqlmp, to create a connection (myConnection) between the
program and the local SQL/MP database:
import java.sql.*;
...
Connection myConnection = DriverManager.getConnection("jdbc:sqlmp:");
Note: You must specify the URL for the driver exactly as it is shown in this and these examples.
Transaction-Aware Driver Example
In a Java program, this code uses the transaction-aware driver, sqlmptx, to create a connection (myConnection)
between the program and the local SQL/MP database:
import java.sql.*;
...
Connection myConnection = DriverManager.getConnection("jdbc:sqlmptx:");
Passing SQL/MP Statements to a Database
When you have a connection between your Java program and an SQL/MP database, you can create an SQL statement
and pass it to the database that returns a result. To create an SQL statement, use the connection's createStatement()
method. To pass the statement to the database, use the statement's executeQuery() method.
Each SQL statement runs as a waited operation, so executing an SQL statement within a thread blocks the JVM.
Note: If your SQL query includes the name of an SQL/MP table, fully qualify the table name in the
query. Otherwise, the volume and subvolume of the table name defaults to the current volume and
subvolume.
In this example, the result set is not cached, so each call to next() retrieves more information from the database:
import java.sql.*;
...
// Create a statement:
Statement myStatement = myConnection.createStatement();
// Pass the string argument directly to the database;
// results are returned in the ResultSet object, r:
ResultSet r = myStatement.executeQuery("SELECT * from $DATA1.DBASE.EMPL");
// Retrieve successive rows from the result set and
// print the first column of each row, which is a String:
while (r.next())
System.out.println("Column 1: " + r.getString(1));
For information about how database transactions are delimited, committed, and rolled back when using JDBC, see
Transactions and the JDBC Driver for SQL/MP.