Google Website Translator Gadget

domingo, 4 de noviembre de 2012

How to get the Java Types from a SQL Type

The Java driver maps by default to BigDecimal, even if a column is defined as NUMBER(15) (which could be mapped to BigInteger)


What could you do to know the mapped Class?


Do a getObject() on the column and check the class.


ResultSet rs = statement.executeQuery("select column from table");
if (rs.next())
{
  Object o = rs.getObject(1);
  System.out.println("Class: " + o.getClass().getName());
}



No hay comentarios:

Publicar un comentario