skip to main content
Configuring Hybrid Data Pipeline for JDBC : Getting started with the JDBC driver : Connecting from an Application to Hybrid Data Pipeline : Connecting using JDBC data sources : Calling a JDBC data source in an application

Try Now
Calling a JDBC data source in an application
Applications can call a JDBC data source using a logical name to retrieve the javax.sql.DataSource object. This object loads the specified driver and can be used to establish a connection to the Hybrid Data Pipeline service.
Once the JDBC data source has been registered with JNDI, it can be used by your JDBC application as shown in the following code example, where myusername and mypassword are the credentials for your Hybrid Data Pipeline user account.
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("Employee");
Connection con = ds.getConnection("myusername","mypassword");
In this example, the JNDI environment is first initialized. Next, the initial naming context is used to find the logical name of the JDBC data source (Employee). The Context.lookup() method returns a reference to a Java object, which is narrowed to a javax.sql.DataSource object. Finally, the DataSource.getConnection() method is called to establish a connection.
Note: If the login credentials of the data store are not stored in the specified data source, the JDBC data source must include them.