Creating the ActiveSpaces JDBC Connection
After registering the ActiveSpaces JDBC driver, the next step is to make the ActiveSpaces JDBC connection.
The DriverManager interface supports the following methods for creating a connection:
Connection getConnection(String url); Connection getConnection(String url, Properties info); Connection getConnection(String url, String user, String password);The url parameter is the JDBC URL to connect to a database, or in our case a data grid. Ensure that the url adheres to the format specified in JDBC URL Format. The info parameter is optional and can contain a set of Java properties that are required for connecting to the data grid. To understand these properties, see ActiveSpaces Connection Properties .
Prerequisites
Procedure
-
After registering the driver, create a JDBC connection to the data grid. To connect to the data grid, you can use any of the
getConnection() methods. The following code snippet uses
Connection getConnection(String url) :
// create a JDBC connection to the data grid String jdbcURL = "jdbc:tibco:tibdg:_default;realmurl= http://localhost:8080"; java.sql.Connection jdbcConnection = java.sql.DriverManager.getConnection(jdbcURL);
An Example of Registering and Connecting to the Data Grid
This examples shows the code snippet to be inserted to your Java code to register and connect to the data grid. The following example uses the Connection getConnection(String url, Properties info) method to create a connection.
public java.sql.Connection getConnection (Properties props) throws SQLException { // Register the ActiveSpaces JDBC Driver with the JDBC DriverManager try { Class.forName("com.tibco.datagrid.jdbc.DriverImpl"); } catch (ClassNotFoundException ex) { // handle exception } // Establish a JDBC connection to the data grid String jdbcURL = "jdbc:tibco:tibdg:_default"; Properties props = new Properties(); props.setProperty( com.tibco.datagrid.Connection.TIBDG_CONNECTION_PROPERTY_STRING_REALMURL, "http://localhost:8080"); return java.sql.DriverManager.getConnection(jdbcURL, props) }
- JDBC URL Format
You specify a JDBC URL when you are establishing a JDBC connection to an ActiveSpaces data grid. - ActiveSpaces Connection Properties
The ActiveSpaces API consists of several properties that can be set when connecting to an ActiveSpaces data grid. These properties control how to connect to the data grid and some of the behaviors of the data grid.
Previous topic: Registering the ActiveSpaces JDBC Driver with the Driver Manager
Copyright © Cloud Software Group, Inc. All rights reserved.