- java.lang.Object
-
- com.pervasive.datarush.jdbc.JDBCConnector
-
- All Implemented Interfaces:
ConnectionSettings
public class JDBCConnector extends Object implements ConnectionSettings
Basic JDBC connector class. Stores information required to create new JDBC connections and provides various common utility methods.
-
-
Constructor Summary
Constructors Constructor Description JDBCConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanupConnection()
Close all resources opened during getConnection()void
closeResultSetAndStatement(String statement, ResultSet rs)
Closes a result set object.void
closeStatement(String statement, PreparedStatement s)
Closes a prepared statement object.ResultSet
executeAndLogSql(String statement, boolean haltOnError, int fetchSize)
Executes a given SQL statement, returning the result.void
executeAndLogStatement(String statement)
Executes the given statement closing the result set when finished.Connection
getConnection()
Creates a JDBC connection as necessary and returns it.ConnectionFactory
getConnectionFactory()
Returns the connection factory to be used for creating connections.String
getDelimiter()
Get the delimiter character.String
getDriverName()
Retrieves the class name of the JDBC driver to use.Password
getEncryptedPassword()
List<String>
getHostNames()
Get the list of configured database host names.DatabaseMetaData
getMetadata()
Gets the database metadata associated with this connection.String
getPassword()
Retrieves the password for connecting to the database.ResultSetMetaData
getTableMetadata()
Gets the metadata associated with this connection's table.ResultSetMetaData
getTableMetadata(String statement)
Gets the metadata associated with the provided statementString
getTableName()
Retrieves the name of the database table to access.String
getUrl()
Retrieves the URL for connecting to the database.String
getUser()
Retrieves the user name for connecting to the database.void
setConnectionFactory(ConnectionFactory connectionFactory)
Sets the connection factory to be used for creating connections.void
setDelimiter(String delimiter)
Set the delimiter character used to delimiter table names in SQL queries.void
setDriverName(String driverName)
Sets the class name of the JDBC driver to use, for example:"sun.jdbc.odbc.JdbcOdbcDriver"
.void
setEncryyptedPassword(Password password)
void
setHostNames(String... hostNames)
Set the list of database host names that can be used to execute queries.void
setHostNames(List<String> hostNames)
Set the list of database host names that can be used to execute queries.void
setPassword(String password)
Sets the password for connecting to the database.void
setTableName(String tableName)
Sets the name of the database table to access.void
setUrl(String url)
Sets the URL for connecting to the database, for example:jdbc:odbc:SampleTest
.void
setUser(String user)
Sets the user name for connecting to the database.boolean
tableExists()
Determine if the table associated with the connection exists
-
-
-
Method Detail
-
setDriverName
public void setDriverName(String driverName)
Sets the class name of the JDBC driver to use, for example:"sun.jdbc.odbc.JdbcOdbcDriver"
.- Parameters:
driverName
- the class name of the JDBC driver to use
-
getDriverName
public String getDriverName()
Retrieves the class name of the JDBC driver to use.- Specified by:
getDriverName
in interfaceConnectionSettings
- Returns:
- the class name of the JDBC driver to use
-
setUser
public void setUser(String user)
Sets the user name for connecting to the database.- Parameters:
user
- the user name for connecting to the database
-
getUser
public String getUser()
Retrieves the user name for connecting to the database.- Specified by:
getUser
in interfaceConnectionSettings
- Returns:
- the user name for connecting to the database
-
setPassword
public void setPassword(String password)
Sets the password for connecting to the database.- Parameters:
password
- the password for connecting to the database
-
setEncryyptedPassword
public void setEncryyptedPassword(Password password)
-
getPassword
public String getPassword()
Retrieves the password for connecting to the database.- Specified by:
getPassword
in interfaceConnectionSettings
- Returns:
- the password for connecting to the database
-
getEncryptedPassword
public Password getEncryptedPassword()
-
setUrl
public void setUrl(String url)
Sets the URL for connecting to the database, for example:jdbc:odbc:SampleTest
.- Parameters:
url
- the URL for connecting to the database
-
getUrl
public String getUrl()
Retrieves the URL for connecting to the database.- Specified by:
getUrl
in interfaceConnectionSettings
- Returns:
- the URL for connecting to the database
-
getTableName
public String getTableName()
Retrieves the name of the database table to access.- Returns:
- the name of the database table to access
-
setTableName
public void setTableName(String tableName)
Sets the name of the database table to access. The table name is required byWriteToJDBC
, but optional forReadFromJDBC
, sinceReadFromJDBC#setSelectStatement(String)
may be used instead.- Parameters:
tableName
- the name of the database table to access
-
getHostNames
public List<String> getHostNames()
Get the list of configured database host names.- Returns:
- database host names
-
setHostNames
public void setHostNames(List<String> hostNames)
Set the list of database host names that can be used to execute queries. This is an optional parameter this is only valid for databases that support multiple database hosts for executing queries.- Parameters:
hostNames
- list of database host names
-
setHostNames
public void setHostNames(String... hostNames)
Set the list of database host names that can be used to execute queries. This is an optional parameter this is only valid for databases that support multiple database hosts for executing queries.- Parameters:
hostNames
- list of database host names
-
setConnectionFactory
public void setConnectionFactory(ConnectionFactory connectionFactory)
Sets the connection factory to be used for creating connections. Defaults toDefaultConnectionFactory
.- Parameters:
connectionFactory
- the connection factory to be used for creating connections.
-
getConnectionFactory
public ConnectionFactory getConnectionFactory()
Returns the connection factory to be used for creating connections. Defaults toDefaultConnectionFactory
.- Returns:
- the connection factory to be used for creating connections.
-
getDelimiter
public String getDelimiter()
Get the delimiter character.- Returns:
- delimiter character
-
setDelimiter
public void setDelimiter(String delimiter)
Set the delimiter character used to delimiter table names in SQL queries.- Parameters:
delimiter
- delimiter character used to surround table names
-
getConnection
public Connection getConnection()
Creates a JDBC connection as necessary and returns it. This is the connection object that is used by all utility methods. If a new connection is required create one using the factory provided by thegetConnectionFactory()
method.- Returns:
- JDBC connection
-
cleanupConnection
public void cleanupConnection()
Close all resources opened during getConnection()- See Also:
getConnection()
-
getMetadata
public DatabaseMetaData getMetadata()
Gets the database metadata associated with this connection.- Returns:
- a DatabaseMetaData object associated with this connection
-
getTableMetadata
public ResultSetMetaData getTableMetadata()
Gets the metadata associated with this connection's table.- Returns:
- a ResultSetMetaData object associated with this connection's table
-
getTableMetadata
public ResultSetMetaData getTableMetadata(String statement)
Gets the metadata associated with the provided statement- Returns:
- a ResultSetMetaData object associated with the statement
-
tableExists
public boolean tableExists()
Determine if the table associated with the connection exists- Returns:
- true if the table exists
-
executeAndLogStatement
public void executeAndLogStatement(String statement)
Executes the given statement closing the result set when finished.- Parameters:
statement
- the statement to execute
-
executeAndLogSql
public ResultSet executeAndLogSql(String statement, boolean haltOnError, int fetchSize)
Executes a given SQL statement, returning the result. Caller is responsible for freeing the result set.- Parameters:
statement
- the statement to executehaltOnError
- if true an error will be thrown if a SQLException is encounteredfetchSize
- the fetch size to use with thePreparedStatement
- Returns:
- the result set
-
closeStatement
public void closeStatement(String statement, PreparedStatement s)
Closes a prepared statement object.- Parameters:
statement
- the original SQL statements
- the prepared statement to close
-
-