Thread: Mismatched JDBC and Java Type
I am using a short (Short) in my application for a particular data field My understanding is that this should map to the JDBC type 'smallInt' which in turn maps to the postgresql type int2. However when I retrieve data via JDBC (jdbc7.0-1.2.jar, 7.0.3-2 engine) the int2 fields are returned as java.lang.Integer instead of java.lang.Short. Is this a bug? ----------- Example code below ---------- ResultSetMetaData md = rs.getMetaData(); while (rs.next()) { for (int c=1; c <= md.getColumnCount(); c++) { Object obj = rs.getObject(c); Logger.println(c + "\tcolumnName=" + md.getColumnName(c) + "\tcolumnType=" + md.getColumnType(c) + "\tcolumnTypeName=" + md.getColumnTypeName(c) + "\tvalue=" + obj + "\tvalueClass=" + obj.getClass().getName() ); will produce ... 10 columnName=active columnType=5 columnTypeName=int2 value=8 valueClass=java.lang.Integer ... note that md.getColumnClassName() is not implemented so I don't know what it would return. =================== Mike Finn Tactical Executive Systems mike.finn@tacticalExecutive.com
At 11:45 27/04/01 -0600, Mike Finn wrote: >I am using a short (Short) in my application for a particular data field >My understanding is that this should map to the JDBC type 'smallInt' which >in turn maps to the postgresql type int2. > >However when I retrieve data via JDBC (jdbc7.0-1.2.jar, 7.0.3-2 engine) >the int2 fields are returned as java.lang.Integer instead of java.lang.Short. Possibly, but it depends on how the JDBC driver is seeing it. It should see int2 as Short. Peter >note that md.getColumnClassName() is not implemented so I don't know what it >would return. Hmm, I'l check 7.1, as I thought it was implemented now... Peter