Package chemaxon.util
Class DatabaseTools
java.lang.Object
chemaxon.util.DatabaseTools
Tools that can be applied in the development of applications
accessing databases.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetFieldNames(ConnectionHandler ch, String tableName, List<String> types) Returns field names in a table.static int[]getFieldTypes(ConnectionHandler ch, String tableName) Returns field types in a table.static booleanChecks if JDBC connection to a database is alive or not.static booleanisIntType(int type) Determines if an SQL type is an integerstatic booleanisRealType(int type) Determines if an SQL type is a non-integer numberstatic booleanisTextType(int type) Determines if an SQL type is a text typestatic byte[]Reads bytes from a ResultSet.static byte[]Reads bytes from a ResultSet.static StringreadString(ResultSet rs, int idx) Reads a String from a ResultSet.
-
Field Details
-
IS_ALIVE_SQL
- See Also:
-
-
Constructor Details
-
DatabaseTools
public DatabaseTools()
-
-
Method Details
-
isConnectionAlive
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
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
Reads bytes from a ResultSet. The structure field can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)- Parameters:
rs- the ResultSetidx- 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
Reads bytes from a ResultSet. The structure field can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)- Parameters:
rs- the ResultSetcolumnName- the name of the field- Returns:
- the structure as a byte array
- Throws:
SQLException- in case of database error, or invalid column type
-
readString
Reads a String from a ResultSet. The field type can be LONGVARBINARY, BLOB or CLOB, VARCHAR(2)- Parameters:
rs- the ResultSetidx- 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
-