Using trusted connections in JDBC
In the previous recipe, we saw why trusted contexts are needed and we also saw how to create a trusted context. Once a trusted context is created, it can be used in various languages to create trusted connections. The infrastructure to create trusted connections is provided by the database drivers for that language. DB2 provides the following drivers that support trusted connections (as of DB2 9.7 GA):
IBM DB2 Driver for JDBC and SQLJ (Type-4 and Type-2 connectivity)
IBM_DB Driver for Ruby
IBM Data Server Provider for .NET
ibm_db2
Driver for PHPCLI/ODBC
In this recipe, we will see how we can establish trusted connections in Java and switch user IDs within a connection. In this recipe, we will use the IBM DB2 driver for JDBC and SQLJ to connect to the database.
Getting ready
The following are the prerequisites for this recipe:
1. Java should be set up and the IBM DB2 driver for JDBC and SQLJ should be available (this driver is shipped with DB2, by default).
2....