Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing Result Set Thats an Integer

 
Joe Brigs
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.
 
K. Tsang
Bartender
Posts: 3585
16
Android 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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic