com.mays.util
Class Sql

java.lang.Object
  extended by com.mays.util.Sql

public class Sql
extends Object

Some convenience methods for doing JDBC.

Author:
Eric Mays

Field Summary
static Logger LOGGER
           
 
Constructor Summary
Sql()
           
 
Method Summary
static int countTable(Connection conn, String name)
          Count the rows
static void createIndex(Connection conn, String table, String column)
          Create the index using the table and column names for the index name
static void createTable(Connection conn, String name, String def)
          Create a table
static void dropTable(Connection conn, String name)
          Drop the table, but catch the "does not exist error", log it, and proceed.
static Connection getConnection()
          Deprecated. 
static Connection getConnection(String schema)
          Deprecated. 
static Connection getConnection(String derby_home, String schema)
          Establish a JDBC connection to an Apache Derby db, creating one if necessary, using the embedded driver.
static Connection getOdbcConnection(String dsn)
          Establish a JDBC connection to an ODBC db Useful for extracting data from MS Access
static void setIntOrNull(PreparedStatement stmt, int parameter_i, String value)
          Set an int parameter on a PreparedStatement from a String, doing the right thing if the string is empty
static void shutdown()
          Deprecated. 
static void shutdown(String schema)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

public static Logger LOGGER
Constructor Detail

Sql

public Sql()
Method Detail

getConnection

public static Connection getConnection(String derby_home,
                                       String schema)
                                throws Exception
Establish a JDBC connection to an Apache Derby db, creating one if necessary, using the embedded driver.

Parameters:
derby_home -
schema -
Returns:
Connection
Throws:
Exception

getConnection

@Deprecated
public static Connection getConnection(String schema)
                                throws Exception
Deprecated. 

Parameters:
schema -
Returns:
Connection
Throws:
Exception

getConnection

@Deprecated
public static Connection getConnection()
                                throws Exception
Deprecated. 

Returns:
Connection
Throws:
Exception

shutdown

public static void shutdown(String schema)
                     throws Exception
Throws:
Exception

shutdown

@Deprecated
public static void shutdown()
                     throws Exception
Deprecated. 

Throws:
Exception

getOdbcConnection

public static Connection getOdbcConnection(String dsn)
                                    throws Exception
Establish a JDBC connection to an ODBC db Useful for extracting data from MS Access

Parameters:
dsn -
Returns:
Connection
Throws:
Exception

dropTable

public static void dropTable(Connection conn,
                             String name)
                      throws Exception
Drop the table, but catch the "does not exist error", log it, and proceed.

Parameters:
conn -
name -
Throws:
Exception

createTable

public static void createTable(Connection conn,
                               String name,
                               String def)
                        throws Exception
Create a table

Parameters:
conn -
name -
def -
Throws:
Exception

countTable

public static int countTable(Connection conn,
                             String name)
                      throws Exception
Count the rows

Parameters:
conn -
name -
Returns:
The row count or -1 is something went wrong (without throwing an Exception)
Throws:
Exception

createIndex

public static void createIndex(Connection conn,
                               String table,
                               String column)
                        throws Exception
Create the index using the table and column names for the index name

Parameters:
conn -
table -
column -
Throws:
Exception

setIntOrNull

public static void setIntOrNull(PreparedStatement stmt,
                                int parameter_i,
                                String value)
                         throws Exception
Set an int parameter on a PreparedStatement from a String, doing the right thing if the string is empty

Parameters:
stmt -
parameter_i -
value -
Throws:
Exception