jBASE jDBC 2.0 Driver (jDBC)


Developers Guide

 

jAgent

jAgent is a server-side jBASE component which must be listening on a user-defined TCP port on the remote jBASE instance. It accepts socket connections to process incoming requests from the JDBC Driver. Please refer to the jAgent user guide and the corresponding section of the knowledgebase for more information on how to configure and start jAgent.

 

 

Connecting to jBASE

JDBC provides two mechanisms to establish a connection to a data source:

 

DriverManager This class requires an application to load the specific JDBC driver which in our case would be the jBASE JDBC Driver. This interface is typically used on a non-managed two-tier deployment scenario where a java naming service is not available.
DataSource This interface is preferred on managed scenarios because JNDI is typically used to lookup a data source. The advantages of having a data source managed by the application are e.g. connection pooling, security and distributed transaction processing for XA-compliant JDBC drivers as is the jBASE JDBC driver.

 

DataSource and DriverManager provide the following methods to create a new connection. For more information on these methods, please read the JDBC API documentation.

 

getConnection(String, url) Obtain a new connection for the specified connection string. Connection properties must be specified inside the connection string.
getConnection(String url, String user, String password) Obtain a new connection for the specified connection string. Connection properties, except user and password must be specified inside the connection string.
getConnection(String url, Properties info) [DriverManager only] Obtain a new connection for the specified connection string. The second parameter specifies the connection properties.

 

 

Authentication

jAgent will attempt to authenticate a user given the user credentials provided to the getConnection() method.

The jBASE JDBC Driver implements the following connection properties to provide user credentials

 

user Specifies the user to be Authenticated
password Specifies the password for the user

 

 

Encryption

jAgent can be configured to use SSL encrypted connections for deployment scenarios which require enhanced security. The jBASE JDBC Driver implements the following connection properties

 

SSL Specifies whether the connection should use SSL encryption. SSL should only be used if the jAgent instance running on the jBASE server has also been configured to accept SSL connections. [Default value=false]
enableNaiveTrustManager Forces the jDBC driver to trust all server certificates

 

 

Examples

 

Example using the DataSource interface:

 

Connection cx = null;

try {

    InitialContext ic = new InitialContext();

    Object cxfObj = ic.lookup("java:comp/env/jdbc/jBaseDB");

    DataSource cxf = (DataSource) cxfObj;

    cx = (Connection) cxf.getConnection();

} catch(NamingException e) {

    // error

}

 

 

Example 1 using the DriverManager interface:

 

//Load jBASE JDBC Driver

Class.forName("com.jbase.jdbc.driver.JBaseJDBCDriver");

 

//Set connection properties and request a new connection

String url = "jdbc:jbase:thin:@127.0.0.1:20002";

Properties cxProps = new Properties();

cxProps.setProperty("user", "test");

cxProps.setProperty("password", "newpassword");

cxProps.setProperty("SSL", "true");                  //Enable SSL

cxProps.setProperty("NaiveTrustManager", "true");

Connection cx = DriverManager.getConnection(url, cxProps);

 

Example 2 using the DriverManager interface:

 

//Load jBASE JDBC Driver

Class.forName("com.jbase.jdbc.driver.JBaseJDBCDriver");

 

//Set connection properties and request a new connection

String url = "jdbc:jbase:thin:@127.0.0.1:20002/MyTestAccount?user=test&password=newpassword&SSL=true&NaiveTrustManager=true";

Connection cx = DriverManager.getConnection(url);

 

 

Closing a connection

After finishing with the connection, it must be closed:

 

cx.close();

 

 

 

JDBC API reference

 

The jBASE JDBC 2.0 Driver implements a subset of the JDBC 2.0 API. Please read the JDBC specification documentation or refer to the JDBC API javadoc documentation for further information.

 

The following example shows how a client application executing an SQL SELECT query and display the obtained result set:

 

Statement stat = null;

try {

    //Create an SQL statement and perform a SQL SELECT query

    stat = cx.createStatement();

    ResultSet rs = stat.executeQuery("SELECT NAME FROM MYTABLE");

 

    //Obtain the meta data associated to the result set to print the no. of columns

    ResultSetMetaData rsMetaData = rs.getMetaData();

    System.out.println("Number of columns: " + rsMetaData.getColumnCount());

 

    //Fetch all rows and display the first column

    while(rs.next()) {

        System.out.println("NAME: " + rs.getString("NAME"));

    }

} catch(SQLException e) {

    throw e;

} finally {

    closeDB(stat);

}

 

 

Further Resources

 

Java JDK http://java.sun.com

 

JDBC Specification and API http://java.sun.com/products/jdbc/download.html

 

J2EE Connector Architecture (JCA) Specification http://java.sun.com/j2ee/connector/

 

JBoss http://www.jboss.org/

 

 

 

           

 


jBASE jDBC 2.0 Driver