org.yajul.sql
Class JdbcHelper

java.lang.Object
  extended by org.yajul.sql.JdbcHelper

public class JdbcHelper
extends java.lang.Object

Utility methods for JDBC.
User: Joshua Davis Date: Sep 9, 2007 Time: 11:29:59 AM


Field Summary
static int COLUMN_NAME_INDEX
           
static int TABLE_NAME_INDEX
           
 
Constructor Summary
JdbcHelper()
           
 
Method Summary
static void close(java.sql.Connection con, java.sql.Statement stmt, java.sql.ResultSet rs)
          Closes the result set, statement, and connection if they are not null.
static java.util.List<java.lang.String> getColumnNames(java.sql.Connection con, java.lang.String tableName)
          Returns all column names in a table as a list of strings.
static java.util.List<java.lang.String> getTableNames(java.sql.Connection con)
          Returns all table names as a list of strings.
static boolean tableExists(java.sql.Connection con, java.lang.String tableName)
          Returns true if the specified table exists.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_NAME_INDEX

public static final int TABLE_NAME_INDEX
See Also:
Constant Field Values

COLUMN_NAME_INDEX

public static final int COLUMN_NAME_INDEX
See Also:
Constant Field Values
Constructor Detail

JdbcHelper

public JdbcHelper()
Method Detail

close

public static void close(java.sql.Connection con,
                         java.sql.Statement stmt,
                         java.sql.ResultSet rs)
Closes the result set, statement, and connection if they are not null. Exceptions will be logged, but ignored. This is typically used in a finally block to clean up after a JDBC connection is used.

Parameters:
con - The connection.
stmt - The statement.
rs - The result set.

getTableNames

public static java.util.List<java.lang.String> getTableNames(java.sql.Connection con)
                                                      throws java.sql.SQLException
Returns all table names as a list of strings.

Parameters:
con - a JDBC connection
Returns:
all table names as a list of strings.
Throws:
java.sql.SQLException - if something went wrong

tableExists

public static boolean tableExists(java.sql.Connection con,
                                  java.lang.String tableName)
Returns true if the specified table exists.

Parameters:
con - The connection.
tableName - The name of the table to look for.
Returns:
boolean - True if the table exists, false if not or if there was a problem.

getColumnNames

public static java.util.List<java.lang.String> getColumnNames(java.sql.Connection con,
                                                              java.lang.String tableName)
                                                       throws java.sql.SQLException
Returns all column names in a table as a list of strings.

Parameters:
con - a JDBC connection
tableName - The table name
Returns:
all column names as a list of strings.
Throws:
java.sql.SQLException - if something went wrong


Copyright © 2008. All Rights Reserved.