Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:56:39+00:00 2026-06-15T08:56:39+00:00

Can anyone see how I’m missuing this ResultSet? I’m getting the below errors from

  • 0

Can anyone see how I’m missuing this ResultSet? I’m getting the below errors from customerID = rs.getInt(1):

public boolean addCustomer(Customer customer) {
    String customerSQL = "INSERT INTO Customer (first_name, last_name)"
            + "VALUES (?, ?)";
    String emailSQL = "INSERT INTO Email (customer_ID, email_address, primary_email)"
            + "VALUES (?,?,?)";
    int customerID = 0;
   
    try (Connection connection = getConnection();
            PreparedStatement customerPs = connection.prepareStatement(
                    customerSQL, new String[] {"CUSTOMER_ID"}); )  {
       
        customerPs.setString(1, customer.getFirstName());
        customerPs.setString(2, customer.getLastName());
        customerPs.executeUpdate();
        ResultSet rs = customerPs.getGeneratedKeys();
       
        System.out.println("Result Set: " + rs.toString());
        customerID = rs.getInt(1);
        System.out.print("Customer ID: " + customerID);
       
    }
    catch(SQLException e)
    {
        System.err.println("Error: " + e);
        e.printStackTrace(System.out);
        return false;
    }
   
    return false;
}

OUTPUT

run:
Bill Joel
this@that.com
those@these.com
wank@that.com

Result Set: org.apache.derby.impl.jdbc.EmbedResultSet40@61c70928
Error: java.sql.SQLException: Invalid cursor state - no current row.
java.sql.SQLException: Invalid cursor state - no current row.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedResultSet.checkOnRow(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedResultSet.getColumn(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedResultSet.getInt(Unknown Source)
        at customeremailmanager.CustomerDB.addCustomer(CustomerDB.java:78)
        at customeremailmanager.CustomerEmailManager.main(CustomerEmailManager.java:24)
Caused by: java.sql.SQLException: Invalid cursor state - no current row.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
        ... 11 more
BUILD SUCCESSFUL (total time: 1 second)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:56:40+00:00Added an answer on June 15, 2026 at 8:56 am

    you have to invoke ResultSet.next() before retriving the rows from your ResultSet Object:

    ResultSet rs = customerPs.getGeneratedKeys();
    while (rs.next()) {
        System.out.println("Result Set: " + rs.toString());
        customerID = rs.getInt(1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone see anything wrong with this login script: public function login($username, $pass, $remember)
Can anyone see if there is something wrong with this? I get no errors
Can anyone see from the following function why I would be getting an Invalid
Can anyone see why I would be getting a NullPointerException with this code? The
Can anyone see why this MySQL command should throw an error? DELETE FROM mytable
I'm at my wit's end with this. Can anyone see anything wrong with this
Does anyone know if this is possible? I can't see to find much info
Can anyone see any reason why IE8 might not run this jQuery? $(#slid).toggle( function()
Can anyone see why this isnt working? For this example the box should turn
Can anyone see why this would work in FF but not Safari? When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.