Follow these steps to integrate the Aster Database JDBC driver into your Java application:
-
Set the CLASSPATH environment variable to include the paths of the JAR files extracted from the Aster Database JDBC driver package.
- Use the Java -classpath flag at the command line to add the paths to the CLASSPATH environment variable. For example, if you place the JAR files in /usr/jars, then add the path like this:
java -classpath /usr/my_program /usr/jars/
or
- Add the paths to the driver to the CLASSPATH environment variable. For example:
export CLASSPATH=/usr/jars/:$CLASSPATH
- Use the Java -classpath flag at the command line to add the paths to the CLASSPATH environment variable. For example, if you place the JAR files in /usr/jars, then add the path like this:
-
In your application:
-
Import the java.sql package like this:
import java.sql.*;
-
Load the driver using the Class.forName() method:
Class.forName("com.asterdata.ncluster.Driver");
-
Define the username, password, and url (including the host, port, and database) parameters, which are needed to connect to the database. For example:
String username = "user"; String password = "password"; String url = "jdbc:ncluster://myhost:2406/database";
For more information about the URL format, see Parameters for Connecting through JDBC. -
Get a Connection instance from JDBC using the DriverManager.getConnection() method:
try { Connection conn = DriverManager.getConnection(url, username, password); } catch (SQLException ex) { // could not connect }
The getConnection method throws a “No driver available SQLException” exception if CLASSPATH does not contain the path for the JDBC driver, or if the parameters are incorrect.
-
Import the java.sql package like this: