chemaxon.util
Class ConnectionHandler

java.lang.Object
  extended by chemaxon.util.ErrorHandler
      extended by chemaxon.util.ConnectionHandler
All Implemented Interfaces:
java.io.Serializable

public class ConnectionHandler
extends ErrorHandler
implements java.io.Serializable

A JavaBean for connecting to relational databases using JDBC. See JDBC home site for more details on JDBC connections. The JDBC driver you are using will provide information on setting the url property.
This JavaBean stores one JChem specific property, the name of the property table. Its default value is "JChemProperties". See the multiuser section for details.

Example:

 ConnectionHandler ch = new ConnectionHandler();
 ch.setDriver("oracle.jdbc.driver.OracleDriver");
 ch.setUrl("jdbc:oracle:thin:@inhale:1521:demodb");
 ch.setLoginName("INTERNAL");
 ch.setPassword("oracle");
 ch.connect();
 

This class can be used as an ActiveX component. To avoid problems caused by exceptions in environments where exceptions can not be handled, using methods with name like <method name>_NE is recommended, (where NE means "no exception"). In that case, exceptions are caught, and stored in the chemaxon.util.ErrorHandler super class.

Author:
Ferenc Csizmadia
See Also:
Serialized Form

Field Summary
 
Fields inherited from class chemaxon.util.ErrorHandler
CLASS_NOT_FOUND_ERROR, DATABASE_SEARCH_ERROR, exception, ILLEGAL_ACCESS_ERROR, INSTANTIATION_ERROR, IO_ERROR, MAX_SEARCH_FREQUENCY_EXCEEDED_ERROR, MOL_FORMAT_ERROR, NO_ERROR, PROPERTY_NOT_SET_ERROR, SQL_ERROR, UNIDENTIFIED_ERROR
 
Constructor Summary
ConnectionHandler()
          Creates new ConnectionHandler
ConnectionHandler(ConnectionHandler ch)
          Creates new ConnectionHandler based on the settings of an other ConnectionHandler.
 
Method Summary
 void close_NE()
          Same as close(), but exceptions are caught and stored.
 void close()
          Closes the connection to the database.
 void connect_NE()
          Same as connect(), but exceptions are caught and stored.
 void connect()
          Connects to the database.
 java.sql.Connection getConnection()
          Getter for property connection.
 java.lang.String getDriver()
          Getter for property driver.
 java.lang.String getLoginName()
          Getter for property loginName.
 java.lang.String getPassword()
          Getter for property password.
 java.lang.String getPropertyTable()
          Getter for property propertyTable.
 boolean getRememberPassword()
          Getter for property rememberPassword.
 java.lang.String getUrl()
          Getter for property url.
 boolean isConnected()
          Getter for property connected.
 boolean loadValuesFromProperties(java.util.Properties settings)
           
 void setConnected(boolean connected)
          Setter for property connected.
 void setConnection(java.sql.Connection con)
          Sets the connection to an externally created Connection
Since connection data (url, driver, loginName, password) is unknown, these properties are set to null !
 void setDriver(java.lang.String driver)
          Setter for property driver.
 void setLoginName(java.lang.String loginName)
          Setter for property loginName.
 void setPassword(java.lang.String password)
          Setter for property password.
 void setPropertyTable(java.lang.String propertyTableName)
          Setter for property propertyTable.
 void setRememberPassword(boolean rememberPassword)
          Setter for property rememberPassword.
 void setUrl(java.lang.String url)
          Setter for property url.
 void storeValuesToProperties(java.util.Properties settings)
           
 
Methods inherited from class chemaxon.util.ErrorHandler
checkError, checkException, getError, getErrorMessage, getException, getStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionHandler

public ConnectionHandler()
Creates new ConnectionHandler


ConnectionHandler

public ConnectionHandler(ConnectionHandler ch)
Creates new ConnectionHandler based on the settings of an other ConnectionHandler. Does not copies Connection, and does not connect.

Parameters:
ch - the other ConnectionHandler
Since:
JChem 2.2
Method Detail

getDriver

public java.lang.String getDriver()
Getter for property driver.

Returns:
Value of property driver.

setDriver

public void setDriver(java.lang.String driver)
Setter for property driver.

Parameters:
driver - New value of property driver.

getUrl

public java.lang.String getUrl()
Getter for property url.

Returns:
Value of property url.

setUrl

public void setUrl(java.lang.String url)
Setter for property url.

Parameters:
url - New value of property url.

getLoginName

public java.lang.String getLoginName()
Getter for property loginName.

Returns:
Value of property loginName.

setLoginName

public void setLoginName(java.lang.String loginName)
Setter for property loginName.

Parameters:
loginName - New value of property loginName.

getPassword

public java.lang.String getPassword()
Getter for property password.

Returns:
Value of property password.

setPassword

public void setPassword(java.lang.String password)
Setter for property password.

Parameters:
password - New value of property password.

getPropertyTable

public java.lang.String getPropertyTable()
Getter for property propertyTable.

Returns:
Value of property propertyTable.

setPropertyTable

public void setPropertyTable(java.lang.String propertyTableName)
Setter for property propertyTable.

Parameters:
propertyTableName - New value of property propertyTable.

getRememberPassword

public boolean getRememberPassword()
Getter for property rememberPassword.

Returns:
Value of property rememberPassword.

setRememberPassword

public void setRememberPassword(boolean rememberPassword)
Setter for property rememberPassword.

Parameters:
rememberPassword - New value of property rememberPassword.

isConnected

public boolean isConnected()
Getter for property connected.

Returns:
Value of property connected.

setConnected

public void setConnected(boolean connected)
                  throws java.sql.SQLException,
                         java.lang.ClassNotFoundException,
                         java.lang.InstantiationException,
                         java.lang.IllegalAccessException
Setter for property connected.

Parameters:
connected - New value of property connected.
Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

getConnection

public java.sql.Connection getConnection()
Getter for property connection.

Returns:
Value of property connection.

setConnection

public void setConnection(java.sql.Connection con)
Sets the connection to an externally created Connection
Since connection data (url, driver, loginName, password) is unknown, these properties are set to null !


connect

public void connect()
             throws java.sql.SQLException,
                    java.lang.ClassNotFoundException,
                    java.lang.InstantiationException,
                    java.lang.IllegalAccessException
Connects to the database.

Throws:
java.sql.SQLException
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

connect_NE

public void connect_NE()
Same as connect(), but exceptions are caught and stored.

See Also:
ErrorHandler, connect()

close

public void close()
           throws java.sql.SQLException
Closes the connection to the database.

Throws:
java.sql.SQLException

close_NE

public void close_NE()
Same as close(), but exceptions are caught and stored.

See Also:
ErrorHandler, close()

loadValuesFromProperties

public boolean loadValuesFromProperties(java.util.Properties settings)

storeValuesToProperties

public void storeValuesToProperties(java.util.Properties settings)