A.18. JDBC and Database Connection Pooling

Basic Steps in Using JDBC

  1. Load the JDBC driver. See http://java.sun.com/products/jdbc/drivers.html for available drivers. Example:

    Class.forName("package.DriverClass");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    
  2. Define the connection URL. The exact format will be defined in the documentation that comes with the particular driver.

    String host = "dbhost.yourcompany.com";
    String dbName = "someName";
    int port = 1234;
    String oracleURL = "jdbc:oracle:thin:@" + host +
                       ":" + port + ":" + dbName;
    String sybaseURL = "jdbc:sybase:Tds:" + host  +
                       ":" + port + ":" + "?SERVICENAME=" +
                       dbName;
    
  3. Establish the connection.

     String username = "jay_debesee"; String password = "secret"; Connection connection = DriverManager.getConnection(oracleURL, ...

Get Core Servlets and JavaServer Pages™ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.