xbn.db
Class DBConnection

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.db.DBConnDirect
              |
              +--xbn.db.DBConnection
All Implemented Interfaces:
Debuggable

public class DBConnection
extends DBConnDirect

Convenience class for handling a single database connection created from the user/pass/JDBC characteristics. See java.sql.Connection.

Source code:  DBConnection.java.  Example code  XmplDBConnection.

Note: When you set a connection directly, via DBConnDirect.setConnection, be aware of the following. If that connection has a different username/password/JDBC characteristics than was passed into the constructor of this class, then if you disconnect and reconnect, you'll be reconnecting to the database using the same user/pass/JDBC characteristics as provided to the constructor of this class.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
DBConnection(String s_username, String s_password, String s_jdbcConnectionString, String s_jdbcDriver, String s_verificationSelect)
          Create a DBConnection.
DBConnection(String s_username, String s_password, String s_jdbcConnectionString, String s_jdbcDriver, String s_verificationSelect, Outputter optr_dbg)
          Create a DBConnection.
 
Method Summary
 void connect()
          Connect to the database, if not already connected.
 void connect(String s_username, String s_password, String s_jdbcConnectionString, String s_jdbcDriver)
          Connect to the database.
 String getDatabasePassword()
          Get the database user's password...
 String getDatabaseUsername()
          Get the database username.
 String getJdbcConnectionString()
          Get the JDBC connection string.
 String getJdbcDriver()
          Get the JDBC driver string.
 String toString()
          Get some information about this DBConnection.
 
Methods inherited from class xbn.db.DBConnDirect
crashIfNotVerified, dbg, dbgnl, disconnect, finalize, getConnection, getConnectionAndSeparate, getOptrDbg, getVerificationSelect, isConnected, isVerified, isVerified, prepareVerificationSelect, setConnection, setOptrDbg, throwAXDbg, throwSQLX
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DBConnection

public DBConnection(String s_username,
                    String s_password,
                    String s_jdbcConnectionString,
                    String s_jdbcDriver,
                    String s_verificationSelect)
             throws SQLException,
                    ClassNotFoundException

Create a DBConnection.

Parameters:
s_verificationSelect - Passed directly to the two-parameter constructor of DBConnDirect.
All - other params passed directly to connect

DBConnection

public DBConnection(String s_username,
                    String s_password,
                    String s_jdbcConnectionString,
                    String s_jdbcDriver,
                    String s_verificationSelect,
                    Outputter optr_dbg)
             throws SQLException,
                    ClassNotFoundException

Create a DBConnection.

This immediately attempts to connect to the database.

Parameters:
s_verificationSelect - Passed directly to the two-parameter constructor of DBConnDirect.
optr_dbg - Passed directly to the two-parameter constructor of DBConnDirect.
All - other params passed directly to connect
Method Detail

connect

public final void connect()
                   throws SQLException,
                          ClassNotFoundException

Connect to the database, if not already connected. You may disconnect and connect repeatedly, although it is process and resource-intensive.

Throws:
AssertException - If isConnected is true.
SQLException - If anything database related goes wrong, such as an incorrect username/password combination.
ClassNotFoundException - If anything is inaccurate with the JDBC driver as you provided into the constructor.

getDatabaseUsername

public String getDatabaseUsername()

Get the database username.

Returns:
s_username exactly as provided to the constructor.

getDatabasePassword

public String getDatabasePassword()

Get the database user's password...

Just kidding. It only returns null.


getJdbcDriver

public String getJdbcDriver()

Get the JDBC driver string.

Returns:
s_jdbcDriver exactly as provided to the constructor.

getJdbcConnectionString

public String getJdbcConnectionString()

Get the JDBC connection string.

Returns:
s_jdbcConnectionString exactly as provided to the constructor.

toString

public String toString()

Get some information about this DBConnection.

Overrides:
toString in class DBConnDirect

connect

public void connect(String s_username,
                    String s_password,
                    String s_jdbcConnectionString,
                    String s_jdbcDriver)
             throws SQLException,
                    ClassNotFoundException

Connect to the database.

If currently connected, then disconnect.

Parameters:
s_username - Database username. If non-null, may not be zero characters in length.
s_password - Database password associated to s_username. If non-null, may not be zero characters in length.
s_jdbcConnectionString - JDBC connection string. May not be null or zero characters in length. For example: jdbc:oracle:thin:@horizon.wharton.upenn.edu:1521:dev". Your database administrator will be able to help you determine what this (parts of it, anyway) needs to be.
s_jdbcDriver - JDBC driver. May not be null or zero characters in length. For example: "oracle.jdbc.driver.OracleDriver"



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo