I have a java application that executes SQL select statements entered by the user on the UI. The application gets the metadata to know the column types:
ResultSetMetaData metadata = rs.getMetaData();
int numColumns = metadata.getColumnCount();
for (int i=1;i<=numColumns;i++){
column[i] = metadata.getColumnType(i);
}
Once I get the result set, for each row I loop through the columns to know the types. Depending on the type I get the values with getInt(), getDate() or getString().
The problem is that in some cases where the select has a large SUM(), there's a numeric overflow when I do getInt() (I get an error from the JDBC driver, Sybase in my case). The problem is that the number to be obtained in getInt() is larger than the capacity of int.
One solution is to use getLong() instead of getInt(), however since I don't know beforehand the select columns as they're entered by the user, I may be using getLong() for very small numeric values, and in large volumes that would be a complete waste of 64-bit fields.
Any ideas how to solve this problem?
Aucun commentaire:
Enregistrer un commentaire