Name

DataSource

Synopsis

Interface Name: javax.sql.DataSource

Superclass: None

Immediate Subclasses: None

Interfaces Implemented: None

Availability: New as of JDK 1.2

Description

This class provides access to a database via JNDI. To get a JDBC connection, you can look up a data source in a JNDI naming or directory service and then grab a connection from that data source.

Class Summary

public interface DataSource {
    java.sql.Connection getConnection( ) 
      throws java.sql.SQLException;
    java.sql.Connection getConnection(String uid, String pw)
      throws java.sql.SQLException;
    int getLoginTimeout( ) throws java.sql.SQLException;
    java.io.PrintWriter getLogWriter( ) 
      throws java.sql.SQLException;
    void setLoginTimeout(int sec) throws java.sql.SQLException;
    void setLogWriter(java.io.PrintWriter pw)
      throws java.sql.SQLException;
}

Object Methods

getConnection( )

public java.sql.Connection getConnection( ) 
  throws java.sql.SQLException;
public java.sql.Connection getConnection(String uid, String pw)
  throws java.sql.SQLException;
Description

These are factory methods for the allocation of a connection to a database from a connection pool.

getLoginTimeout( ) and setLoginTimeout( )

public int getLoginTimeout( ) throws java.sql.SQLException;
public void setLoginTimeout(int sec) 
  throws java.sql.SQLException;
Description

These methods get and set a connection for the interval that the system waits to establish before giving up. This value is an interval in seconds. A value of zero directs the data source to depend on ...

Get Database Programming with JDBC & Java, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.