Getting Integer field value from JChem DB

User 2793f13b08

23-08-2007 20:15:08

Pardon the silly question but...





Code:
PreparedStatement pstmt = c.prepareStatement(sql);


   ResultSet rs = pstmt.executeQuery();


   if (rs.next())


        {


      System.out.println("ID: "+byteArrayToInt((DatabaseTools.readBytes(rs, 1))));


   }






Is there a method that will get me that CD_ID value? Is it because the CD_ID is an index that I cannot retrieve it?





DatabaseTools only has readString and readBytes. How do I handle Integer field types? This code give me an exception as follows:


Code:



Exception in thread "main" java.sql.SQLException: Cannot handle type in field "cd_id": java.lang.Integer


   at chemaxon.util.DatabaseTools.readBytesOrString(DatabaseTools.java:248)


   at chemaxon.util.DatabaseTools.readBytes(DatabaseTools.java:168)


   at chemaxon.util.DatabaseTools.readBytes(DatabaseTools.java:141)


   at ligandcalculations.CalculateLigandProperties.main(CalculateLigandProperties.java:96)






Also, could you direct me to the API which has the description of the field types? I'd like to know what the numbers mean...
Quote:



fieldName: CD_ID and type: 4


fieldName: CD_STRUCTURE and type: -4


fieldName: CD_SMILES and type: -1


fieldName: CD_LIGAND_ID and type: -1


fieldName: CD_FORMULA and type: 12


fieldName: CD_MOLWEIGHT and type: 8


fieldName: CD_HASH and type: 4


fieldName: CD_FLAGS and type: 12


fieldName: CD_TIMESTAMP and type: 93
Thank you and sorry if this has been answered before. A quick search in the forum didn't get me any answers.





Omar

ChemAxon 9c0afc9aaf

24-08-2007 07:58:23

Hi,





DatabaseTools.readString() and readBytes() are convenience methods mainly for retrieving the value of the cd_structure field (where the original structure source is stored for display).


They are needed because this field can have multiple types, e.g. under Oracle it was historically LONG RAW, but now BLOB is the default for new tables and CLOB is also supported.


These calls can handle all three types transparently.





For other columns you may simply use the standard JDBC calls, for example:





Code:
ResultSet rs = ...;


...


int myInteger = rs.getInt(1);
Quote:
Also, could you direct me to the API which has the description of the field types? I'd like to know what the numbers mean...
The JDBC API is part of the Java API (look in the "java.sql" package):





http://java.sun.com/javase/6/docs/api/index.html





The type constants can be found in this class:





http://java.sun.com/javase/6/docs/api/java/sql/Types.html





The values can be found here:





http://java.sun.com/javase/6/docs/api/constant-values.html#java.sql.Types.INTEGER





I also suggest reading a JDBC tutorial, e.g.:





http://java.sun.com/docs/books/tutorial/jdbc/





JDBC is a nice and friendly (easy to learn) database access API.





Best regards,





Szilard