org.jscience.util
Class JDBC

java.lang.Object
  extended by org.jscience.util.JDBC
All Implemented Interfaces:
ThirdParty

public final class JDBC
extends java.lang.Object
implements ThirdParty

The class JDBC provides some simplified access to existing ODBC and MySQL drivers through static methods. Although the class doesn't require any additional driver software for compilation, certain methods may through SQLException if the specified driver is not present at the time.

See Also:
JDBCTableModel

Method Summary
static void copyConnection(java.sql.Connection from, java.sql.Connection to)
          copies all tables from one connection into the other connection
static void copyTable(java.sql.Connection from, java.sql.Connection to, java.lang.String table)
          creates a new table in Connection to corresponding to the given table in Connection from and transfers all data
static java.lang.String createTableString(java.sql.ResultSetMetaData data, java.lang.String tableName)
          creates the DDL statement that would create a table identical to the one denoted by the given meta data
static java.sql.Connection getMySQLConnection(java.lang.String dbName)
          returns getMySQLConnection("localhost", dbName)
static java.sql.Connection getMySQLConnection(java.lang.String host, java.lang.String dbName)
          provides simplified access to a MySQL database using the MySQL Connector/J 3.1 driver.
static java.sql.Connection getMySQLConnection(java.lang.String host, java.lang.String dbName, java.lang.String login, java.lang.String password)
          provides simplified access to a MySQL database using MySQL Connector/J 3.1
static java.sql.Connection getODBCConnection(java.lang.String dbName)
          provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge
static java.sql.Connection getODBCConnection(java.lang.String dbName, java.lang.String login, java.lang.String password)
          provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge
static java.sql.ResultSet getResultSet(java.sql.Connection con, java.lang.String tableName)
          DOCUMENT ME!
static java.sql.Connection getSQLServerConnection(java.lang.String host, java.lang.String dbName, java.lang.String login, java.lang.String password)
          getSQLServerConnection() provides access to a Microsoft SQL-Server database directly through the JDBC driver provided by Microsoft
static java.util.Vector<java.util.Vector<java.lang.Object>> getTable(java.sql.Connection con, java.lang.String tableName)
          retrieves the entire table and returns it as a Vector of rows containing Vectors with the column values per row
static java.lang.String[] getTableNames(java.sql.Connection con)
          DOCUMENT ME!
static java.lang.String[] getViews(java.sql.Connection con)
          DOCUMENT ME!
static int insert(java.sql.Connection con, java.lang.String tableName, java.lang.Object[] values)
          inserts the given values as a single row into the given table of the given connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

insert

public static int insert(java.sql.Connection con,
                         java.lang.String tableName,
                         java.lang.Object[] values)
                  throws java.sql.SQLException
inserts the given values as a single row into the given table of the given connection.
It is assumed that the given vaules correspond to the columns found in the table specified by the connection and the table name.

Parameters:
con - DOCUMENT ME!
tableName - DOCUMENT ME!
values - DOCUMENT ME!
Returns:
the row count for the insert statement
Throws:
java.sql.SQLException - DOCUMENT ME!

getTableNames

public static java.lang.String[] getTableNames(java.sql.Connection con)
                                        throws java.sql.SQLException
DOCUMENT ME!

Parameters:
con - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

getViews

public static java.lang.String[] getViews(java.sql.Connection con)
                                   throws java.sql.SQLException
DOCUMENT ME!

Parameters:
con - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

getResultSet

public static java.sql.ResultSet getResultSet(java.sql.Connection con,
                                              java.lang.String tableName)
                                       throws java.sql.SQLException
DOCUMENT ME!

Parameters:
con - DOCUMENT ME!
tableName - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

getTable

public static java.util.Vector<java.util.Vector<java.lang.Object>> getTable(java.sql.Connection con,
                                                                            java.lang.String tableName)
                                                                     throws java.sql.SQLException
retrieves the entire table and returns it as a Vector of rows containing Vectors with the column values per row

Parameters:
con - DOCUMENT ME!
tableName - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

getMySQLConnection

public static java.sql.Connection getMySQLConnection(java.lang.String dbName)
                                              throws java.sql.SQLException
returns getMySQLConnection("localhost", dbName)

Throws:
java.sql.SQLException
See Also:
getMySQLConnection(String, String)

getMySQLConnection

public static java.sql.Connection getMySQLConnection(java.lang.String host,
                                                     java.lang.String dbName)
                                              throws java.sql.SQLException
provides simplified access to a MySQL database using the MySQL Connector/J 3.1 driver. If the MySQL driver is not present, this method will throw a RuntimeException.

Parameters:
host - hostname; unless a port is specified, 3306 is used
dbName - name of the database
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.lang.RuntimeException - DOCUMENT ME!

getMySQLConnection

public static java.sql.Connection getMySQLConnection(java.lang.String host,
                                                     java.lang.String dbName,
                                                     java.lang.String login,
                                                     java.lang.String password)
                                              throws java.sql.SQLException
provides simplified access to a MySQL database using MySQL Connector/J 3.1

Parameters:
host - DOCUMENT ME!
dbName - DOCUMENT ME!
login - DOCUMENT ME!
password - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.lang.RuntimeException - DOCUMENT ME!

getODBCConnection

public static java.sql.Connection getODBCConnection(java.lang.String dbName)
                                             throws java.sql.SQLException
provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge

Parameters:
dbName - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.lang.RuntimeException - DOCUMENT ME!

getODBCConnection

public static java.sql.Connection getODBCConnection(java.lang.String dbName,
                                                    java.lang.String login,
                                                    java.lang.String password)
                                             throws java.sql.SQLException
provides some simplified access to existing ODBC connections through Sun's JDBC/ODBC bridge

Parameters:
dbName - DOCUMENT ME!
login - DOCUMENT ME!
password - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.lang.RuntimeException - DOCUMENT ME!

getSQLServerConnection

public static java.sql.Connection getSQLServerConnection(java.lang.String host,
                                                         java.lang.String dbName,
                                                         java.lang.String login,
                                                         java.lang.String password)
                                                  throws java.sql.SQLException
getSQLServerConnection() provides access to a Microsoft SQL-Server database directly through the JDBC driver provided by Microsoft

Parameters:
host - DOCUMENT ME!
dbName - DOCUMENT ME!
login - DOCUMENT ME!
password - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!
java.lang.RuntimeException - DOCUMENT ME!

copyTable

public static void copyTable(java.sql.Connection from,
                             java.sql.Connection to,
                             java.lang.String table)
                      throws java.sql.SQLException
creates a new table in Connection to corresponding to the given table in Connection from and transfers all data

Parameters:
from - DOCUMENT ME!
to - DOCUMENT ME!
table - DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

copyConnection

public static void copyConnection(java.sql.Connection from,
                                  java.sql.Connection to)
                           throws java.sql.SQLException
copies all tables from one connection into the other connection

Parameters:
from - DOCUMENT ME!
to - DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!

createTableString

public static java.lang.String createTableString(java.sql.ResultSetMetaData data,
                                                 java.lang.String tableName)
                                          throws java.sql.SQLException
creates the DDL statement that would create a table identical to the one denoted by the given meta data

Parameters:
data - DOCUMENT ME!
tableName - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.sql.SQLException - DOCUMENT ME!