JDBC/SQL problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: JDBC/SQL problem

  1. #1
    Fabio Luis De Paoli Guest

    JDBC/SQL problem

    In the piece of code below I'm getting an SQL error I can't understand:

    // discover if the legal person already exists in the database
    step = new String("looking for LegalPerson - before prepare");
    anSQL = new String("select count(*) from lp "
    + "where taxid_root = ? "
    + "and type = ?");
    aStmt = aConnex.prepareStatement(anSQL) ;

    tempTaxID = embryo.getBranchTaxID();
    tempRoot = tempTaxID.getRootNumber(); // is equal to (int)
    58890252
    aStmt.setInt(1, tempRoot); // sets the parameter to (int)
    58890252
    aStmt.setString(2, "J");
    aResult = aStmt.executeQuery();
    int numLPs = aResult.getInt(1);

    This is the error I get, when the last line is executed:

    *** SQLException caught ***
    looking for LegalPerson - before execute
    Message: No current row
    SQLState: IX000
    Vendor: -79739

    java.lang.NullPointerException
    at legalPersonManagement.TesterLPManager.main(TesterLPManager.java:52)
    at symantec.tools.debug.MainThread.run(Agent.java:48)

    The expected result was to get (int) 1, because there is a register in the
    table that matches my select criteria... Does anybody know what this error
    means and how to circumvent it? I've checked the JDBC api, the Informix
    JDBC programmer's guide, etc...

    I'm using JDK 1.1 (VisualCafé 3, jdk 1.1.7) with Informix JDBC 1.5. I'm
    debugging in Win32 (in VisualCafé) and the database server is Informix
    Dynamic Server 7.30 UC6 running on HP-UX 10.20.

    Any help will be greatly appreciated. Best regards,

    Fabio Luis De Paoli
    fpaoli@sao-co.br.dhl.com
    Business Consultant for Ops/CS
    DHL Worldwide Express, GRU-CO, Brazil


    Attached Files Attached Files

  2. #2
    Paul Clapham Guest

    Re: JDBC/SQL problem


    Fabio Luis De Paoli <fpaoli@sao-co.br.dhl.com> wrote in message
    news:391C0415.ABFA4E1@sao-co.br.dhl.com...
    > In the piece of code below I'm getting an SQL error I can't understand:
    >
    > // discover if the legal person already exists in the database

    ....
    > aResult = aStmt.executeQuery();
    > int numLPs = aResult.getInt(1);
    >
    > This is the error I get, when the last line is executed:
    >
    > *** SQLException caught ***
    > looking for LegalPerson - before execute
    > Message: No current row

    ....
    > The expected result was to get (int) 1, because there is a register in the
    > table that matches my select criteria... Does anybody know what this error
    > means and how to circumvent it? I've checked the JDBC api, the Informix
    > JDBC programmer's guide, etc...
    >

    ....
    Don't you need to do "aResult.next()" to read the first row returned?




  3. #3
    Fabio Luis De Paoli Guest

    Re: JDBC/SQL problem

    Christian/Paul,

    Thanks for the pointers! You are right, I was missing the aResult.next(); I
    guess I didn't figure this out before because all my previous uses of JDBC
    involved queries with more than one result and in that case I always started
    using the ResultSet with:
    while (aResult.next()) { .....
    }
    Get the picture?

    Thanks for the help. Best regards,

    Fabio



    Paul Clapham wrote:

    > Fabio Luis De Paoli <fpaoli@sao-co.br.dhl.com> wrote in message
    > news:391C0415.ABFA4E1@sao-co.br.dhl.com...
    > > In the piece of code below I'm getting an SQL error I can't understand:
    > >
    > > // discover if the legal person already exists in the database

    > ...
    > > aResult = aStmt.executeQuery();
    > > int numLPs = aResult.getInt(1);
    > >
    > > This is the error I get, when the last line is executed:
    > >
    > > *** SQLException caught ***
    > > looking for LegalPerson - before execute
    > > Message: No current row

    > ...
    > > The expected result was to get (int) 1, because there is a register in the
    > > table that matches my select criteria... Does anybody know what this error
    > > means and how to circumvent it? I've checked the JDBC api, the Informix
    > > JDBC programmer's guide, etc...
    > >

    > ...
    > Don't you need to do "aResult.next()" to read the first row returned?


    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center