Exahusted Resultset error when data is present

Discussion in 'Java' started by Becker, Apr 19, 2004.

  1. Becker

    Becker Guest

    I am attempting to pull data from a database via a servlet. I have
    verified that my SQL works and that there is data in the database
    (exactly one row for each query that I'm interested in). When I
    restart the webserver my servlet works wonderfully. However when I go
    back and click on a second item I get a ExahustedResultset error. I
    have renamed my conn/stmt/rs variable names in this servlet to make
    sure they are unique. I have verifed with cut-n-paste that my SQL is
    fine. There is one row for each query in the database. I have tried
    rs.first() rs.last() rs.absolute(1) but the second time I use the
    servlet, it fails.

    Any ideas?

    Code is below. Some name have been changed to protect the guilty.




    --------------

    public class Foo extends HttpServlet {

    public void init() throws ServletException {


    super.init();
    username="username";
    password="password";
    query1 = "select stuff from lotsofstuff"
    jdbc_class = "oracle.jdbc.driver.OracleDriver";
    jdbc_url = "jdbc:eek:racle:thin:mad:asysadm10:1521:MACHINENAME";

    }

    public synchronized void service(HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    {

    try {
    Connection conA = null;
    Statement stmtA = null;
    ResultSet rsA = null;
    String variableName = null;

    Class.forName(jdbc_class);
    conA = DriverManager.getConnection(jdbc_url, username,
    password);

    DatabaseMetaData dma = conA.getMetaData();

    rsA = stmtA.executeQuery(query1);

    if ( rsA.next() ) {
    variableName = rsA.getString(1);
    }


    /********* I have attempted to add in the following, but it doesn't
    work
    else {
    rsA.first();
    variableName = rsA.getString(1);
    }
    **********/
    stmtA.clearBatch();

    rsA.close();
    stmtA.close();
    conA.close();

    rsA = null;
    stmtA = null;
    conA = null;

    }

    catch (SQLException ex) {
    ex.printStackTrace();
    }
    Becker, Apr 19, 2004
    #1
    1. Advertising

  2. Becker

    Bryce (Work) Guest

    On 19 Apr 2004 11:31:18 -0700, (Becker) wrote:

    >I am attempting to pull data from a database via a servlet. I have
    >verified that my SQL works and that there is data in the database
    >(exactly one row for each query that I'm interested in). When I
    >restart the webserver my servlet works wonderfully. However when I go
    >back and click on a second item I get a ExahustedResultset error. I
    >have renamed my conn/stmt/rs variable names in this servlet to make
    >sure they are unique. I have verifed with cut-n-paste that my SQL is
    >fine. There is one row for each query in the database. I have tried
    >rs.first() rs.last() rs.absolute(1) but the second time I use the
    >servlet, it fails.
    >
    >Any ideas?
    >
    >Code is below. Some name have been changed to protect the guilty.
    >
    >
    >
    >
    >--------------
    >
    >public class Foo extends HttpServlet {
    >
    > public void init() throws ServletException {
    >
    >
    > super.init();
    > username="username";
    > password="password";
    > query1 = "select stuff from lotsofstuff"
    > jdbc_class = "oracle.jdbc.driver.OracleDriver";
    > jdbc_url = "jdbc:eek:racle:thin:mad:asysadm10:1521:MACHINENAME";
    >
    > }


    Just a suggestion, you may want to look at configuring your container
    for datasources, then retrieving a connection is as easy as:
    Context initialContext = new InitialContext()
    DataSource ds =
    (DataSource)initialContext.lookup("java:comp/env/jdbc/myds");

    Connection conn = ds.getConnection();

    and then you can setup the configuration in your config files...

    > public synchronized void service(HttpServletRequest req,
    >HttpServletResponse res)
    > throws ServletException, IOException
    > {
    >
    > try {
    > Connection conA = null;
    > Statement stmtA = null;
    > ResultSet rsA = null;
    > String variableName = null;
    >
    > Class.forName(jdbc_class);
    > conA = DriverManager.getConnection(jdbc_url, username,
    >password);
    >
    > DatabaseMetaData dma = conA.getMetaData();
    >
    > rsA = stmtA.executeQuery(query1);


    I don't see you setting stmtA.... Did you leave part of your code out?


    > if ( rsA.next() ) {
    > variableName = rsA.getString(1);
    > }



    Shouldn't need the next part...

    >/********* I have attempted to add in the following, but it doesn't
    >work
    > else {
    > rsA.first();
    > variableName = rsA.getString(1);
    > }
    >**********/
    > stmtA.clearBatch();
    >
    > rsA.close();
    > stmtA.close();
    > conA.close();
    >
    > rsA = null;
    > stmtA = null;
    > conA = null;
    >
    > }
    >
    > catch (SQLException ex) {
    > ex.printStackTrace();
    > }



    --
    now with more cowbell
    Bryce (Work), Apr 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Helixpoint
    Replies:
    8
    Views:
    544
    Marina
    Jun 26, 2003
  2. Brent Burkart
    Replies:
    2
    Views:
    6,020
    MS News \(MS ILM\)
    Aug 20, 2003
  3. Matthew Louden
    Replies:
    2
    Views:
    8,110
    Val Mazur
    Nov 25, 2003
  4. Biebel
    Replies:
    3
    Views:
    5,273
    Sudsy
    Nov 21, 2003
  5. Ralf Wahner
    Replies:
    5
    Views:
    630
    Bob Foster
    Dec 24, 2003
Loading...

Share This Page