This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Closing Result Set Thats an Integer

 
Ranch Hand
Posts: 70
IBM DB2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing insert into database and I define the result set as integer and set it to zero before I call method to execute the SQL. If I have a result set thats a string I check to see if its NOT null. But how do you check when you return an integer. I know this is very simple but my brain is blocking it. I've serached the internet but I'm confused with some of the answers.
 
Bartender
Posts: 3648
16
Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are misunderstanding the concept of result set.

What you currently have, the "rs" variable is not the ResultSet object, just an integer. The "db" variable is most likely the Statement object.

Therefore, it is not needed to close the "rs". But closing the Statement and DB connection is recommended.

A more understandable code with meaningful variable names will look like:



From the javax.sql.Statement, the executeQuery(sql) will return a ResultSet. While the executeUpdate(sql) will return an integer.

ResultSet executeQuery(String sql)
throws SQLException

Executes the given SQL statement, which returns a single ResultSet object.



int executeUpdate(String sql)
throws SQLException

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.


 
Men call me Jim. Women look past me to this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!