org.alicebot.server.sql.pool
Class DbAccess

java.lang.Object
  extended by org.alicebot.server.sql.pool.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.
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 connection)
          Constructs a DbAccess object given a Connection object.
DbAccess(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
          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 connection)
          Sets the Connection object used by this object.
 void setDriver(java.lang.String driver)
          Sets the name of the driver to be used by this object.
 void setPassword(java.lang.String password)
          Sets the password to be used by this object.
 void setUrl(java.lang.String url)
          Sets the URL string to be used by this object.
 void setUser(java.lang.String user)
          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

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 driver,
                java.lang.String url,
                java.lang.String user,
                java.lang.String password)
Constructs a DbAccess object given a driver, url, user name and password.

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

DbAccess

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

Parameters:
connection - 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.

Throws:
java.sql.SQLException - if the connection cannot be made
java.lang.ClassNotFoundException - if the driver class cannot be found

executeQuery

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

Parameters:
query - the query to execute
Returns:
the ResultSet from executing a given query
Throws:
java.sql.SQLException - if there was a problem.

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 connection)
Sets the Connection object used by this object.

Parameters:
connection - the Connection object to be used

setDriver

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

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

setPassword

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

Parameters:
password - the password to be used

setUrl

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

Parameters:
url - the URL string to be used

setUser

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

Parameters:
user - the user name to be used