Package chemaxon.util

Class DatabaseTools

java.lang.Object
chemaxon.util.DatabaseTools

@PublicAPI public class DatabaseTools extends Object
Tools that can be applied in the development of applications accessing databases.
  • Field Details

  • Constructor Details

    • DatabaseTools

      public DatabaseTools()
  • Method Details

    • isConnectionAlive

      public static boolean isConnectionAlive(Connection con)
      Checks if JDBC connection to a database is alive or not. Especially useful if a database server may time out JDBC connections that have not been used for a long time.
      Parameters:
      con - the connect to test
      Returns:
      true if the connection is alive
    • getFieldNames

      public static List<String> getFieldNames(ConnectionHandler ch, String tableName, List<String> types) throws SQLException
      Returns field names in a table.
      Parameters:
      ch - ConnectionHandler opened to the database.
      tableName - the name of the database table.
      types - ArrayList object to store type names in it.
      Returns:
      the list of field names.
      Throws:
      SQLException - if it occurs
    • getFieldTypes

      public static int[] getFieldTypes(ConnectionHandler ch, String tableName) throws SQLException
      Returns field types in a table.
      Parameters:
      ch - ConnectionHandler opened to the database.
      tableName - the name of the database table.
      Returns:
      the field types in a table, in order
      Throws:
      SQLException - if it occurs
      Since:
      JChem 2.0
    • isTextType

      public static boolean isTextType(int type)
      Determines if an SQL type is a text type
      Parameters:
      type - the SQL type
      Returns:
      true, if the specified type is a text type
      Since:
      JChem 2.0
    • isIntType

      public static boolean isIntType(int type)
      Determines if an SQL type is an integer
      Parameters:
      type - the SQL type
      Returns:
      true, if the specified type is an integer type
      Since:
      JChem 2.0
    • isRealType

      public static boolean isRealType(int type)
      Determines if an SQL type is a non-integer number
      Parameters:
      type - the SQL type
      Returns:
      true, if the specified type is a non-integer number
      Since:
      JChem 2.0
    • readBytes

      public static byte[] readBytes(ResultSet rs, int idx) throws SQLException
      Reads bytes from a ResultSet. The structure field can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)
      Parameters:
      rs - the ResultSet
      idx - the index of the field (first column is 1)
      Returns:
      the data as a byte array
      Throws:
      SQLException - in case of database error, or invalid column type
    • readBytes

      public static byte[] readBytes(ResultSet rs, String columnName) throws SQLException
      Reads bytes from a ResultSet. The structure field can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)
      Parameters:
      rs - the ResultSet
      columnName - the name of the field
      Returns:
      the structure as a byte array
      Throws:
      SQLException - in case of database error, or invalid column type
    • readString

      public static String readString(ResultSet rs, int idx) throws SQLException
      Reads a String from a ResultSet. The field type can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)
      Parameters:
      rs - the ResultSet
      idx - the index of the field (first column is 1)
      Returns:
      the structure as a String.
      Throws:
      SQLException - in case of database error, or invalid column type
      Since:
      JChem 3.2