com.fdsapi
Class DataAccessClient

java.lang.Object
  |
  +--com.fdsapi.DataAccessBase
        |
        +--com.fdsapi.DataAccessClient
All Implemented Interfaces:
DataAccess

public class DataAccessClient
extends DataAccessBase

Class used to connect to a JDBC data source using direct JDBC connections in lieu of javax.sql.DataSource. Sample creation of a DataAccess object in Sybase, and MySQL:

  DataAccess da=null;

  // Sybase ASE database server
  da = new DataAccessClient("com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:sc2000:5000/databasename", "myusername", "mypassword", false);

  // Sybase ASA database server (Note that it is same as ASE)
  da = new DataAccessClient("com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:127.0.0.1:2638/ASADemoDB", "myusername", "mypassword", false);
  
  // MySQL database server.  Alternative constructor.
  da=new DataAccessClient("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/databasename?user=root", false);

 

Note the boolean cacheConnection determines if the connection should be closed after each db interaction. For example when a ResultSet is retrieved. Setting the boolean to true caches the connection (i.e. leaves it open). Note this class is not thread safe and a DataAccessClient would have to be created for each Thread.



View Code


Field Summary
 
Fields inherited from class com.fdsapi.DataAccessBase
connection, resultSet, statement
 
Constructor Summary
DataAccessClient(java.lang.String dbDriver, java.lang.String dbUrl, boolean cacheConnection)
          Provide url only, which will include the username and password.
DataAccessClient(java.lang.String dbDriver, java.lang.String dbUrl, java.util.Properties info, boolean cacheConnection)
          provide Properties
DataAccessClient(java.lang.String dbDriver, java.lang.String dbUrl, java.lang.String userName, java.lang.String passWord, boolean cacheConnection)
           
 
Method Summary
 void close()
          Close open Statements, ResultSets and the Connection
 DataAccess createInstance()
          Factory method that allows this class to clone itself
 java.sql.Connection getConnection()
          Get database connection
 
Methods inherited from class com.fdsapi.DataAccessBase
closeConnection, closeResultSet, closeStatement, connectionIsClosed, createStatement, executeQuery, executeUpdate, getDataSourceName, getResultSet, getResultSetConverter, setDataSourceName, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataAccessClient

public DataAccessClient(java.lang.String dbDriver,
                        java.lang.String dbUrl,
                        java.lang.String userName,
                        java.lang.String passWord,
                        boolean cacheConnection)
                 throws java.sql.SQLException

DataAccessClient

public DataAccessClient(java.lang.String dbDriver,
                        java.lang.String dbUrl,
                        boolean cacheConnection)
                 throws java.sql.SQLException
Provide url only, which will include the username and password.


DataAccessClient

public DataAccessClient(java.lang.String dbDriver,
                        java.lang.String dbUrl,
                        java.util.Properties info,
                        boolean cacheConnection)
                 throws java.sql.SQLException
provide Properties

Method Detail

createInstance

public DataAccess createInstance()
                          throws java.sql.SQLException
Factory method that allows this class to clone itself

java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Get database connection

java.sql.SQLException

close

public void close()
           throws java.sql.SQLException
Close open Statements, ResultSets and the Connection

Specified by:
close in interface DataAccess
Overrides:
close in class DataAccessBase
java.sql.SQLException