Class DBUtils
- java.lang.Object
-
- repast.simphony.freezedry.datasource.DBUtils
-
public class DBUtils extends Object
Utility methods for connecting to and working with databases.- Author:
- Jerry Vos
-
-
Constructor Summary
Constructors Constructor Description DBUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
doesTableExist(Connection con, String tableName)
Checks if the table of the specified name exists.static List<String>
getColumnNames(Connection con, String tableName)
Retrieves the names of the columns of the specified table.static DataSource
getDataSource(String userName, String password, String dbURL, String driverName)
static DataSource
getDataSource(DBConnectionInfo info)
Gets a data source pointing to a database.static boolean
validateConnectionSettings(DBConnectionInfo info, String infoMessage)
-
-
-
Method Detail
-
getDataSource
public static DataSource getDataSource(DBConnectionInfo info) throws ClassNotFoundException
Gets a data source pointing to a database. The data source is aPoolingDataSource
with a connection pool that will automatically grow when all of its members are in use and another is requested.- Parameters:
connectionString
- the connection string for the database (its URL)userName
- the username (if necessary)password
- the username (if necessary)driver
- the driver to be used for connecting to the database- Returns:
- a
PoolingDataSource
- Throws:
ClassNotFoundException
- when the driver can't be loaded
-
doesTableExist
public static boolean doesTableExist(Connection con, String tableName) throws SQLException
Checks if the table of the specified name exists.- Parameters:
con
- the connection to the databasetableName
- the name of the table- Returns:
- if the table exists or not
- Throws:
SQLException
- when there is a problem querying the database
-
getColumnNames
public static List<String> getColumnNames(Connection con, String tableName) throws SQLException
Retrieves the names of the columns of the specified table.- Parameters:
con
- the connection to the databasetableName
- the name of the database's table- Returns:
- a list of column names
- Throws:
SQLException
-
validateConnectionSettings
public static boolean validateConnectionSettings(DBConnectionInfo info, String infoMessage)
-
getDataSource
public static DataSource getDataSource(String userName, String password, String dbURL, String driverName) throws ClassNotFoundException
- Throws:
ClassNotFoundException
-
-