KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to INSERT several rows using a PreparedStatement : ps = con.prepareStatement(query,PreparedStatement.RETURN_GENERATED_KEYS); for(Element e:listOfElements){ ps.setString(1,this.col_val_1); ps.setString(2,this.col_val_2); ps.setInt(3,this.col_val_3); ps.addBatch(); } ps.executeBatch(); ResultSet rs = ps.getGeneratedKeys(); At this point, whent I expect to get the PK's generated for each INSERT , I get this SQLServerException : com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be executed before any results can be obtained. I expected to get a ResultSet with one row for each insert performed, so I could get each PK generated. Am I expecting wrong? Am I doing something wrong? Can it be done in a different way using batch execution?
Tags (comma-separated)
Save Edits
Cancel