• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to get BIGINT return type in Java

 
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying a query

. . . "SELECT COUNT(*) FROM member"

and kept getting SQLExceptions.
I had first tried that as a myResultSet.getInt(1) call, but it was no better when I tried it as getLong(1) or getObject(1).
I got the details from ResultSetMetaData and it said column 1 was type -5 (typeName = BIGINT) and its name was COUNT(*), so that wasn't the problem.

I am using InnoDB on MySQL5.0.51.

I presume count(*) returns a bigint (That is what it says in the MySQL manual �11.11.1 page 719 and it doesn't say anything about unsigned) and I thought a bigint corresponds to a long.
I ended up using a workaround, because I already knew the count(*) for that table, but it's hardly satisfactory hard-coding such a number.

Stack Trace:
SQL Exception: stack trace follows: state: S1000, error code: 00000
java.sql.SQLException
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:815)
at com.mysql.jdbc.UpdatableResultSet.checkRowPos(UpdatableResultSet.java:226)
at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2835)
at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:2830)
at database.CreditUnionTestInserter.makeLotsOfPayments(CreditUnionTestInserter.java:148)
at database.CreditUnionTestInserter.main(CreditUnionTestInserter.java:224)

Changing to TYPE_SCROLL_INSENSITIVE didn't make any difference.

Anybody know why I was getting that exception?
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you didn't call rs.next() to move to the first row of the ResultSet.
 
Campbell Ritchie
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that all? Thank you. Too late to try it tonight, but will try again tomorrow.
 
Campbell Ritchie
Marshal
Posts: 65755
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again. You were right; it worked all right after a next() call.
 
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!