JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

Implementations of the DataSource Interface

This section provides a summary of implementations of the DataSource interface by different JDBC drivers.

JDBC is recommending that the DataSource interface should be used to create database connection objects instead of using the DriverManager class. Many JDBC have provided implementations of the DataSource interfaces. A quick summary of various implementations of the DataSource interface is provided here as a comparison and a reference:

Driver Name: Apache Derby Network Client JDBC Driver
------------
Driver JAR File: derbyclient.jar
DataSource Class: org.apache.derby.jdbc.ClientDataSource
DataSource Example:
  ClientDataSource ds 
    = new org.apache.derby.jdbc.ClientDataSource();
  ds.setServerName("localhost");
  ds.setPortNumber(1527);
  ds.setDatabaseName("TestDB");
  Connection con = ds.getConnection();

Driver Name: JDBC-ODBC Bridge
------------
Driver JAR File: None (included in Java SE 1.6)
DataSource Class: sun.jdbc.odbc.ee.DataSource
DataSource Example:
      sun.jdbc.odbc.ee.DataSource ds 
        = new sun.jdbc.odbc.ee.DataSource();
      ds.setDatabaseName("HY_ACCESS");

Driver Name: MySQL Connctor/J 
------------
Driver JAR File: mysql-connector-java-5.0.7-bin.jar
DataSource Class: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
DataSource Example:
  com.mysql.jdbc.jdbc2.optional.MysqlDataSource ds 
    = new com.mysql.jdbc.jdbc2.optional.MysqlDataSource();
  ds.setServerName("localhost");
  ds.setPortNumber(3306);
  ds.setDatabaseName("HerongDB");
  ds.setUser("Herong");
  ds.setPassword("TopSecret");
  Connection con = ds.getConnection();

Driver Name: Oracle JDBC Thin client-side driver
------------
Driver JAR File: ojdbc14.jar
DataSource Class: oracle.jdbc.pool.OracleDataSource
DataSource Example:
  oracle.jdbc.pool.OracleDataSource ds 
    = new oracle.jdbc.pool.OracleDataSource();
  ds.setDriverType("thin");
  ds.setServerName("localhost");
  ds.setPortNumber(1521);
  ds.setDatabaseName("XE"); // Oracle SID
  ds.setUser("Herong");
  ds.setPassword("TopSecret");
  Connection con = ds.getConnection();

Driver Name: Miscrosoft JDBC Driver
------------
Driver JAR File: sqljdbc.jar
DataSource Class: com.microsoft.sqlserver.jdbc.SQLServerDataSource
DataSource Example:
  com.microsoft.sqlserver.jdbc.SQLServerDataSource  ds 
    = new com.microsoft.sqlserver.jdbc.SQLServerDataSource();
  ds.setServerName("localhost");
  ds.setPortNumber(1269);
  ds.setDatabaseName("AdventureWorksLT");
  ds.setUser("sa");
  Connection con = ds.getConnection();

Sections in This Chapter

JDBC Drivers Tested with Java SE 1.6

Connection URL Formats and Examples

Implementations of the DataSource Interface

Performances on Inserting Rows

Dr. Herong Yang, updated in 2007
Implementations of the DataSource Interface