com.holub.database.jdbc
Class JDBCConnection

java.lang.Object
  extended by com.holub.database.jdbc.adapters.ConnectionAdapter
      extended by com.holub.database.jdbc.JDBCConnection
All Implemented Interfaces:
Connection

public class JDBCConnection
extends ConnectionAdapter

A limited version of the Connection class. All methods undocumented base-class overrides throw a SQLException if called.

Note that you can't mix non-autocommit behavior with explicit SQL begin/commit statements. For example, if you turn off autocommit mode (which causes a SQL begin to be issued), and then execute a SQL begin manually, a call to `commit` will commit the inner transaction, but not the outer one. In effect, you can't do nested transactions using the JDBC commit() or rollback() methods.

©2004 Allen I. Holub. All rights reserved.

This code may be used freely by yourself with the following restrictions:

  1. Your splash screen, about box, or equivalent, must include Allen Holub's name, copyright, and URL. For example:

    This program contains Allen Holub's SQL package.
    (c) 2005 Allen I. Holub. All Rights Reserved.
    http://www.holub.com


    If your program does not run interactively, then the foregoing notice must appear in your documentation.
  2. You may not redistribute (or mirror) the source code.
  3. You must report any bugs that you find to me. Use the form at http://www.holub.com/company/contact.html or send email.
  4. The software is supplied as is. Neither Allen Holub nor Holub Associates are responsible for any bugs (or any problems caused by bugs, including lost productivity or data) in any of this code.

Field Summary
 
Fields inherited from interface java.sql.Connection
TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE
 
Constructor Summary
JDBCConnection(String uri)
           
JDBCConnection(URI uri)
           
 
Method Summary
 void close()
          Close a database connection.
 void commit()
          Terminate the current transactions and start a new one.
 Statement createStatement()
           
 boolean getAutoCommit()
          Return true if auto-commit mode is enabled
 void rollback()
          Roll back the current transactions and start a new one.
 void setAutoCommit(boolean enable)
          Once set true, all SQL statements form a stand-alone transaction.
 
Methods inherited from class com.holub.database.jdbc.adapters.ConnectionAdapter
clearWarnings, createStatement, createStatement, getCatalog, getHoldability, getMetaData, getTransactionIsolation, getTypeMap, getWarnings, isClosed, isReadOnly, nativeSQL, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCatalog, setHoldability, setReadOnly, setSavepoint, setSavepoint, setTransactionIsolation, setTypeMap
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCConnection

public JDBCConnection(String uri)
               throws SQLException,
                      URISyntaxException,
                      IOException
Throws:
SQLException
URISyntaxException
IOException

JDBCConnection

public JDBCConnection(URI uri)
               throws SQLException,
                      IOException
Throws:
SQLException
IOException
Method Detail

close

public void close()
           throws SQLException
Close a database connection. A commit is issued automatically if auto-commit mode is disabled.

Specified by:
close in interface Connection
Overrides:
close in class ConnectionAdapter
Throws:
SQLException
See Also:
setAutoCommit(boolean)

createStatement

public Statement createStatement()
                          throws SQLException
Specified by:
createStatement in interface Connection
Overrides:
createStatement in class ConnectionAdapter
Throws:
SQLException

commit

public void commit()
            throws SQLException
Terminate the current transactions and start a new one. Does nothing if auto-commit mode is on.

Specified by:
commit in interface Connection
Overrides:
commit in class ConnectionAdapter
Throws:
SQLException
See Also:
setAutoCommit(boolean)

rollback

public void rollback()
              throws SQLException
Roll back the current transactions and start a new one. Does nothing if auto-commit mode is on.

Specified by:
rollback in interface Connection
Overrides:
rollback in class ConnectionAdapter
Throws:
SQLException
See Also:
setAutoCommit(boolean)

setAutoCommit

public void setAutoCommit(boolean enable)
                   throws SQLException
Once set true, all SQL statements form a stand-alone transaction. A begin is issued automatically when auto-commit mode is disabled so that the commit() and rollback() methods will work correctly. Similarly, a commit is issued automatically when auto-commit mode is enabled.

Auto-commit mode is on by default.

Specified by:
setAutoCommit in interface Connection
Overrides:
setAutoCommit in class ConnectionAdapter
Throws:
SQLException

getAutoCommit

public boolean getAutoCommit()
                      throws SQLException
Return true if auto-commit mode is enabled

Specified by:
getAutoCommit in interface Connection
Overrides:
getAutoCommit in class ConnectionAdapter
Throws:
SQLException