I try get some data from oracle db, put this data in json and use it in other place, but i have problem with converting timestamptz. Oracle give me timestamp with timezone in string format like "23.10.14 18:34:16,000000 ASIA/NOVOSIBIRSK". Here some piece of my code.
public void loadFromDb(ResultSet resultSet, Connection oc) throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
Object obj = resultSet.getObject(i);
if (obj == null)
continue;
if (obj instanceof TIMESTAMPTZ) {
TIMESTAMPTZ ts = (TIMESTAMPTZ) obj;
if (oc != null) {
super.setValue(metaData.getColumnName(i), ts.stringValue(oc));
} else {
super.setValue(metaData.getColumnName(i), ts.stringValue());
}
}
}
and i get this exception
java.sql.SQLException: Conversion to String failed
at oracle.sql.Datum.stringValue(Datum.java:181)
btw, earlier i get timezone in number format like 'XX:XX' and this code not work too, but work this magic super.setValue(metaData.getColumnName(i), ts.stringValue(null))
now this way thtows nullpointerexception.
Please help me, because i tried all which found in javadocs.