Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As per the docs: </p> <blockquote> <p>By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.</p> </blockquote> <p><a href="http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html</a></p> <p>You're iterating through your <code>ResultSet</code> and reusing the same <code>Statement</code> to do your <code>INSERT</code>. As soon as you execute the insert, the <code>ResultSet</code> you're iterating through is closed, and the next call to <code>rs.next()</code> throws that exception. You would need to use a new <code>Statement</code> to execute your insert query inside the loop. </p> <p>That said, you really should be using prepared statements for your SQL. It's cleaner in terms of reading your code, and far less error prone as they handle any necessary quoting for you.</p> <pre><code>String statementString = "INSERT INTO viewOrder VALUES (?,?,?,?,?,?,?,?)"; PreparedStatement pStmt= con.prepareStatement(statementString); while(rs.next()) { pStmt.setString(1, rs.getString("title_name")); pStmt.setFloat(2, rs.getFloat("price")); pStmt.setInt(3, rs.getInt("pages")); pStmt.setString(4, rs.getString("au_fname")); pStmt.setString(5, rs.getString("au_lname")); pStmt.setString(6, rs.getString("pub_name")); pStmt.setString(7, rs.getString("city")); pStmt.setString(8, rs.getString("country")); pStmt.execute(); totalPrice = totalPrice + rs.getFloat("price"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload