But in real a java.math.BigDecimal is returned. Either the
documentation must be updated or the return type must be changed.
I propose to change the return type to java.lang.Long because this
keeps compatibility with MySQL.
I am using release 1.2.129.
> But in real a java.math.BigDecimal is returned
...when you call which method?
Regards,
Thomas
BigDecimal is returned from ResultSet.getObject(columnIndex).
I can't reproduce it. My test case returns java.lang.Long:
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.h2.tools.DeleteDbFiles;
public class TestSimple {
public static void main(String... args) throws Exception {
org.h2.Driver.load();
DeleteDbFiles.execute("data", null, true);
Connection conn;
conn = DriverManager.getConnection(
"jdbc:h2:data/test", "sa", "sa");
Statement stat = conn.createStatement();
stat.execute("create table test(id bigint)");
stat.execute("insert into test values(1)");
ResultSet rs = stat.executeQuery(
"select * from test");
rs.next();
Object o = rs.getObject(1);
System.out.println(o.getClass().getName());
conn.close();
}
}
Regards,
Thomas
Here is the test case:
package db;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.h2.tools.DeleteDbFiles;
public class BigintLongTest
{
public static void main(String[] args) throws Exception
{
org.h2.Driver.load();
DeleteDbFiles.execute("data", null, true);
Connection conn;
conn = DriverManager.getConnection("jdbc:h2:data/test", "sa",
"sa");
Statement stat = conn.createStatement();
String createSQL = "CREATE TABLE test (id BIGINT);";
stat.execute(createSQL);
stat.execute("insert into test values (1)");
// Returns BigDecimal
String query = "SELECT GREATEST(id, " +
((long)Integer.MAX_VALUE) + ") FROM test";
ResultSet rs = stat.executeQuery(query);
rs.next();
Object o = rs.getObject(1);
System.out.println(o.getClass().getName());
// Returns Long
String query2 = "SELECT GREATEST(id, " +
((long)Integer.MAX_VALUE + 1) + ") FROM test";
ResultSet rs2 = stat.executeQuery(query2);
rs2.next();
Object o2 = rs2.getObject(1);
System.out.println(o2.getClass().getName());
conn.close();
}
}
GREATEST returns Long for all Java-Integer values and BigDecimal for
all values greater Java-Integer range.
I don't know if that's correct or not.
MySQL returns Long for both queries.
Uli
Christian Peter found the problem. This will be fixed in the next release.
Regards,
Thomas