BIGINT mapped to java.math.BigDecimal instead of java.lang.Long

2,712 views
Skip to first unread message

u.wi...@gematronik.com

unread,
Mar 1, 2010, 9:22:17 AM3/1/10
to H2 Database
The documentation (http://www.h2database.com/html/
datatypes.html#bigint_type) tells me that the BIGINT type is mapped to
java.lang.Long. The same is done in MySQL.

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.

Thomas Mueller

unread,
Mar 2, 2010, 2:36:24 PM3/2/10
to h2-da...@googlegroups.com
Hi,

> But in real a java.math.BigDecimal is returned

...when you call which method?

Regards,
Thomas

u.wi...@gematronik.com

unread,
Mar 3, 2010, 3:25:34 AM3/3/10
to H2 Database
>
> > But in real a java.math.BigDecimal is returned
>
> ...when you call which method?
>
Hi Thomas,

BigDecimal is returned from ResultSet.getObject(columnIndex).

Thomas Mueller

unread,
Mar 4, 2010, 3:46:15 PM3/4/10
to h2-da...@googlegroups.com
Hi,

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

u.wi...@gematronik.com

unread,
Mar 5, 2010, 8:01:59 AM3/5/10
to H2 Database
You are right.
I have tracked it down from my application.
The problem is the GREATEST method and not the BIGINT type.

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

Thomas Mueller

unread,
Mar 8, 2010, 1:23:10 PM3/8/10
to h2-da...@googlegroups.com
Hi,

Christian Peter found the problem. This will be fixed in the next release.

Regards,
Thomas

u.wi...@gematronik.com

unread,
Mar 9, 2010, 2:50:27 AM3/9/10
to H2 Database
Great!
Thank you very much!
Uli
Reply all
Reply to author
Forward
0 new messages