• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to store the count value returned froma sql query into a variable for future use?

 
Ranch Hand
Posts: 86
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was facing an error in storing the row count obtained from sql into a variable i displayed the one file running code below along with output. i was wondering if you guys could help me with this error. I want to count the no of customers and then append it to a string and generate the customer id.



I want to get he count of customers from a table in oracle 11g db and store it in a variable. I am unable to do so. Please can anyone help me? I have shown the snippet of the code i am trying to write...

OUTPUT:
Connection Successfull
sun.jdbc.odbc.JdbcOdbcConnection@39b27b
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(Unknown Source)
at components.genrateid.generateid(genrateid.java:29)
at components.genrateid.main(genrateid.java:43)
 
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, your class name, genrateid, is too similar to your function name, generateid. It's confusing.

How do you know you're unable to get the row count? Have you printed the value of the variable "count" to verify it?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before you can access the columns from a row of the ResultSet, you have to call "rs.next()" to move to that row. Since your query is guaranteed to return exactly one row, just call rs.next() before you try to get data from the ResultSet and leave it at that. Normally you use rs.next() to control a loop (you've seen the JDBC tutorials, right?) but in this case a loop isn't necessary.
 
Yuta Lolap
Ranch Hand
Posts: 86
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! I solved it!
reply
    Bookmark Topic Watch Topic
  • New Topic