org.aitools.programd.util.sql
Class DbAccess

java.lang.Object
  extended by org.aitools.programd.util.sql.DbAccess

public class DbAccess
extends java.lang.Object

Represents all connection details to a DBMS and allows for getting the input/output streams.

Uses JDBC so as to support any DBMS with a JDBS driver. For use with another DBMS one should change the classname for the Java Driver and the specific URL.

Sample:

 
  
   
    
      driver class name : "oracle.jdbc.dnlddriver.OracleDriver"
      specific URL : "dbc:oracle:dnldthin:@ora.doxa.ro:1526:ORCL".
      
    
   
  
 

Author:
Cristian Mircioiu

Field Summary
protected  java.sql.Connection connection
          The Connection used by this object.
protected  java.lang.String driver
          The name of the driver used by this object.
private static java.lang.String LINE_SEPARATOR
           
private static org.apache.log4j.Logger logger
           
protected  java.lang.String password
          The password used by this object.
protected  java.sql.Statement statement
          The statement used by this object.
protected  java.lang.String url
          The URL string used by this object.
protected  java.lang.String user
          The user name used by this object.
 
Constructor Summary
DbAccess(java.sql.Connection connectionToUse)
          Constructs a DbAccess object given a Connection object.
DbAccess(java.lang.String driverToUse, java.lang.String urlToUse, java.lang.String userToUse, java.lang.String passwordToUse)
          Constructs a DbAccess object given a driver, url, user name and password.
 
Method Summary
 void connect()
          Connects to the database using the values of the fields already set in this object.
 java.sql.ResultSet executeQuery(java.lang.String query)
          Returns the ResultSet from executing a given query.
 int executeUpdate(java.lang.String update)
          Returns the ResultSet from executing a given update.
 java.sql.Connection getConnection()
          Returns the Connection object used by this object.
 java.lang.String getDriver()
          Returns the name of the driver used by this object.
 java.lang.String getPassword()
          Returns the password used by this object.
 java.sql.Statement getStatement()
          Returns the Statement object used by this object.
 java.lang.String getUrl()
          Returns the URL string used by this object.
 java.lang.String getUser()
          Returns the user name used by this object.
 void setConnection(java.sql.Connection connectionToSet)
          Sets the Connection object used by this object.
 void setDriver(java.lang.String driverToSet)
          Sets the name of the driver to be used by this object.
 void setPassword(java.lang.String passwordToSet)
          Sets the password to be used by this object.
 void setUrl(java.lang.String urlToSet)
          Sets the URL string to be used by this object.
 void setUser(java.lang.String userToSet)
          Sets the user name to be used by this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.log4j.Logger logger

LINE_SEPARATOR

private static final java.lang.String LINE_SEPARATOR

connection

protected java.sql.Connection connection
The Connection used by this object.


statement

protected java.sql.Statement statement
The statement used by this object.


driver

protected java.lang.String driver
The name of the driver used by this object.


url

protected java.lang.String url
The URL string used by this object.


user

protected java.lang.String user
The user name used by this object.


password

protected java.lang.String password
The password used by this object.

Constructor Detail

DbAccess

public DbAccess(java.lang.String driverToUse,
                java.lang.String urlToUse,
                java.lang.String userToUse,
                java.lang.String passwordToUse)
Constructs a DbAccess object given a driver, url, user name and password.

Parameters:
driverToUse - name of the class representing the Driver to be used by the Driver manager
urlToUse - location of a data source name (dsn)
userToUse - user name
passwordToUse - password for user

DbAccess

public DbAccess(java.sql.Connection connectionToUse)
Constructs a DbAccess object given a Connection object.

Parameters:
connectionToUse - the Connection object from which to construct the DbAccess object
Method Detail

connect

public void connect()
Connects to the database using the values of the fields already set in this object.


executeQuery

public java.sql.ResultSet executeQuery(java.lang.String query)
Returns the ResultSet from executing a given query.

Parameters:
query - the query to execute
Returns:
the ResultSet from executing a given query

executeUpdate

public int executeUpdate(java.lang.String update)
Returns the ResultSet from executing a given update.

Parameters:
update - the update to execute
Returns:
the row count resulting from executing a given update

getConnection

public java.sql.Connection getConnection()
Returns the Connection object used by this object.

Returns:
the Connection object used by this object.

getDriver

public java.lang.String getDriver()
Returns the name of the driver used by this object.

Returns:
the name of the driver used by this object.

getPassword

public java.lang.String getPassword()
Returns the password used by this object.

Returns:
the password used by this object.

getStatement

public java.sql.Statement getStatement()
Returns the Statement object used by this object.

Returns:
the Statement object used by this object.

getUrl

public java.lang.String getUrl()
Returns the URL string used by this object.

Returns:
the URL string used by this object.

getUser

public java.lang.String getUser()
Returns the user name used by this object.

Returns:
the user name used by this object.

setConnection

public void setConnection(java.sql.Connection connectionToSet)
Sets the Connection object used by this object.

Parameters:
connectionToSet - the Connection object to be used

setDriver

public void setDriver(java.lang.String driverToSet)
Sets the name of the driver to be used by this object.

Parameters:
driverToSet - the name of the driver to be used

setPassword

public void setPassword(java.lang.String passwordToSet)
Sets the password to be used by this object.

Parameters:
passwordToSet - the password to be used

setUrl

public void setUrl(java.lang.String urlToSet)
Sets the URL string to be used by this object.

Parameters:
urlToSet - the URL string to be used

setUser

public void setUser(java.lang.String userToSet)
Sets the user name to be used by this object.

Parameters:
userToSet - the user name to be used