Package com.blackrook.sql
Class SQLConnector
java.lang.Object
com.blackrook.sql.SQLConnector
Core database JDBC connector object.
From this object, representing a potential link to a remote (or local) database, connections can be spawned.
- Author:
- Matthew Tropiano
-
Constructor Summary
ConstructorsConstructorDescriptionSQLConnector(String className, String jdbcURL) Constructs a new database connector.SQLConnector(String className, String jdbcURL, String userName, String password) Constructs a new database connector.SQLConnector(String className, String jdbcURL, Properties info) Constructs a new database connector. -
Method Summary
Modifier and TypeMethodDescriptionReturns a new, opened JDBC Connection using the credentials stored with this connector.voidgetConnectionAnd(SQLConnectionConsumer handler) Creates a connection, passes it to the providedSQLConnectionConsumerfunction, then closes it.<R> RgetConnectionAnd(SQLConnectionFunction<R> handler) Creates a connection, passes it to the providedSQLConnectionFunction, calls it, closes it, and returns the result.Returns the full JDBC URL for this specific connector.
-
Constructor Details
-
SQLConnector
Constructs a new database connector.- Parameters:
className- The fully qualified class name of the driver.jdbcURL- The JDBC URL to use.- Throws:
RuntimeException- if the driver class cannot be found.
-
SQLConnector
Constructs a new database connector.- Parameters:
className- The fully qualified class name of the driver.jdbcURL- The JDBC URL to use.info- the set ofPropertiesto pass along to the JDBCDriverManager.- Throws:
RuntimeException- if the driver class cannot be found.
-
SQLConnector
Constructs a new database connector.- Parameters:
className- The fully qualified class name of the driver.jdbcURL- The JDBC URL to use.userName- the username.password- the password.- Throws:
RuntimeException- if the driver class cannot be found.
-
-
Method Details
-
getJDBCURL
Returns the full JDBC URL for this specific connector. This differs by implementation and driver.- Returns:
- the URL
-
getConnection
Returns a new, opened JDBC Connection using the credentials stored with this connector.- Returns:
- a
DriverManager-created connection. - Throws:
SQLException- if a connection can't be procured.- See Also:
-
getConnectionAnd
Creates a connection, passes it to the providedSQLConnectionConsumerfunction, then closes it.- Parameters:
handler- the consumer function that accepts the retrieved connection.- Throws:
SQLException- if a connection cannot be re-created or re-established.
-
getConnectionAnd
Creates a connection, passes it to the providedSQLConnectionFunction, calls it, closes it, and returns the result.- Type Parameters:
R- the return type.- Parameters:
handler- the consumer function that accepts the retrieved connection and returns a value.- Returns:
- the return value of the handler function.
- Throws:
SQLException- if a connection cannot be re-created or re-established.
-