Class DBUtils
java.lang.Object
repast.simphony.freezedry.datasource.DBUtils
Utility methods for connecting to and working with databases.
- Author:
- Jerry Vos
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
doesTableExist
(Connection con, String tableName) Checks if the table of the specified name exists.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
Gets a data source pointing to a database.static boolean
validateConnectionSettings
(DBConnectionInfo info, String infoMessage)
-
Constructor Details
-
DBUtils
public DBUtils()
-
-
Method Details
-
getDataSource
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
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
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
-
getDataSource
public static DataSource getDataSource(String userName, String password, String dbURL, String driverName) throws ClassNotFoundException - Throws:
ClassNotFoundException
-