Same ResultSet results references

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oaklander
    New Member
    • Aug 2007
    • 20

    Same ResultSet results references

    Is it okay to keep creating queries with the same ResultSet Object reference (results)? Here is what I am currently using in my Database statements with Oracle and everything works but was wondering if this is okay where I am using ResultSet results for 3 queries in my Tomcat container:

    Code:
    ResultSet results = null;
    Statement statement = null;
    ......
            statement = connection.createStatement();
            results = statement.executeQuery("select name from tableone");
            if(results.next())
            {
                 int myvar = ....
            }
     
            results = statement.executeQuery("select food, sugar from tabletwo");
            if(results.next())
            {
                 int myvar2 = ....
            }
     
            results = statement.executeQuery("select rock from tablethree");
            if(results.next())
            {
                 int myvar3 = ....
            }
     
            ...
            //close results, statement and connection object references
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by oaklander
    Is it okay to keep creating queries with the same ResultSet Object reference (results)? Here is what I am currently using in my Database statements with Oracle and everything works but was wondering if this is okay where I am using ResultSet results for 3 queries in my Tomcat container:

    Code:
    ResultSet results = null;
    Statement statement = null;
    ......
            statement = connection.createStatement();
            results = statement.executeQuery("select name from tableone");
            if(results.next())
            {
                 int myvar = ....
            }
     
            results = statement.executeQuery("select food, sugar from tabletwo");
            if(results.next())
            {
                 int myvar2 = ....
            }
     
            results = statement.executeQuery("select rock from tablethree");
            if(results.next())
            {
                 int myvar3 = ....
            }
     
            ...
            //close results, statement and connection object references
    Yes it's fine. Just make sure you properly close all connections after you are done using them.

    Comment

    Working...