Class DBUtils
java.lang.Object
repast.simphony.freezedry.datasource.DBUtils
Utility methods for connecting to and working with databases.
- Author:
- Jerry Vos
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandoesTableExist(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 DataSourcegetDataSource(String userName, String password, String dbURL, String driverName) static DataSourceGets a data source pointing to a database.static booleanvalidateConnectionSettings(DBConnectionInfo info, String infoMessage)
-
Constructor Details
-
DBUtils
public DBUtils()
-
-
Method Details
-
getDataSource
Gets a data source pointing to a database. The data source is aPoolingDataSourcewith 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
-