Class JKDriverManagerDataSource

java.lang.Object
com.jk.core.jdbc.JKDriverManagerDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class JKDriverManagerDataSource extends Object implements DataSource
This class provides method to help in managing the driver connection.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKDriverManagerDataSource

      public JKDriverManagerDataSource(String url, String user, String password)
      Instantiates a new JK driver manager data source.
      Parameters:
      url - the url
      user - the user
      password - the password
    • JKDriverManagerDataSource

      public JKDriverManagerDataSource()
      This method constructs a new JKDriverManagerDataSource.
  • Method Details

    • getLogWriter

      public PrintWriter getLogWriter() throws SQLException

      Retrieves the log writer for this DataSource object.

      The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created, the log writer is initially null; in other words, the default is for logging to be disabled.

      Specified by:
      getLogWriter in interface CommonDataSource
      Specified by:
      getLogWriter in interface DataSource
      Returns:
      the log writer for this data source or null if logging is disabled
      Throws:
      SQLException - if a database access error occurs
    • setLogWriter

      public void setLogWriter(PrintWriter out) throws SQLException

      Sets the log writer for this DataSource object to the given java.io.PrintWriter object.

      The log writer is a character output stream to which all logging and tracing messages for this data source will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source- specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created the log writer is initially null; in other words, the default is for logging to be disabled.

      Specified by:
      setLogWriter in interface CommonDataSource
      Specified by:
      setLogWriter in interface DataSource
      Parameters:
      out - the new log writer; to disable logging, set to null
      Throws:
      SQLException - if a database access error occurs
    • setLoginTimeout

      public void setLoginTimeout(int seconds) throws SQLException

      Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise, it specifies that there is no timeout. When a DataSource object is created, the login timeout is initially zero.

      Specified by:
      setLoginTimeout in interface CommonDataSource
      Specified by:
      setLoginTimeout in interface DataSource
      Parameters:
      seconds - the data source login time limit
      Throws:
      SQLException - if a database access error occurs.
    • getLoginTimeout

      public int getLoginTimeout() throws SQLException
      Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise, it means that there is no timeout. When a DataSource object is created, the login timeout is initially zero.
      Specified by:
      getLoginTimeout in interface CommonDataSource
      Specified by:
      getLoginTimeout in interface DataSource
      Returns:
      the data source login time limit
      Throws:
      SQLException - if a database access error occurs.
    • getParentLogger

      public Logger getParentLogger() throws SQLFeatureNotSupportedException
      Return the parent Logger of all the Loggers used by this data source. This should be the Logger farthest from the root Logger that is still an ancestor of all of the Loggers used by this data source. Configuring this Logger will affect all of the log messages generated by the data source. In the worst case, this may be the root Logger.
      Specified by:
      getParentLogger in interface CommonDataSource
      Returns:
      the parent Logger for this data source
      Throws:
      SQLFeatureNotSupportedException - if the data source does not use java.util.logging
    • unwrap

      public <T> T unwrap(Class<T> iface) throws SQLException

      This method is to be implemented (TBI), currently it only return null.

      Specified by:
      unwrap in interface Wrapper
      Type Parameters:
      T - Specifies the type of the class modeled by this Class object.
      Parameters:
      iface - Represents a Class defining an interface that the result must implement.
      Returns:
      null.
      Throws:
      SQLException - if a database access error occurs.
    • isWrapperFor

      public boolean isWrapperFor(Class<?> iface) throws SQLException

      This method is to be implemented (TBI), currently it only return false.

      Specified by:
      isWrapperFor in interface Wrapper
      Parameters:
      iface - Specifies a Class defining an interface.
      Returns:
      false.
      Throws:
      SQLException - if a database access error occurs.
    • getConnection

      public Connection getConnection() throws SQLException

      Attempts to establish a connection with the data source that this DataSource object represents.

      Specified by:
      getConnection in interface DataSource
      Returns:
      a connection to the data source
      Throws:
      SQLException - if a database access error occurs
      SQLTimeoutException - when the driver has determined that the timeout value specified by the setLoginTimeout method has been exceeded and has at least tried to cancel the current database connection attempt
    • getConnection

      public Connection getConnection(String username, String password) throws SQLException

      Attempts to establish a connection with the data source that this DataSource object represents.

      Specified by:
      getConnection in interface DataSource
      Parameters:
      username - the database user on whose behalf the connection is being made
      password - the user's password
      Returns:
      a connection to the data source
      Throws:
      SQLException - if a database access error occurs
      SQLTimeoutException - when the driver has determined that the timeout value specified by the setLoginTimeout method has been exceeded and has at least tried to cancel the current database connection attempt
    • getUrl

      public String getUrl()
      This method gets the connection URL.
      Returns:
      the connection URL.
    • setUrl

      public void setUrl(String url)
      This method replaces the current connection URL.
      Parameters:
      url - Specifies the new URL.
    • getUser

      public String getUser()
      This method gets the user name on whose behave this connection is being made.
      Returns:
      the user name on whose behave this connection is being made.
    • setUser

      public void setUser(String user)
      This method replaces the user name on whose behave this connection is being made.
      Parameters:
      user - Specifies the new user.
    • getPassword

      public String getPassword()
      This method gets the password associated with the user of this connection.
      Returns:
      the password associated with the user.
    • setPassword

      public void setPassword(String password)
      This method replaces the password associated with the user.
      Parameters:
      password - Specifies the new password.