Reputation: 627
I'm using PreparedStatement
to batch insert into a MySQL database. Then I need the query to return the values of one specific column (name) for the successfully inserted rows. I have already tried:
preparedStatement = connection.prepareStatement("INSERT INTO x (id,name) VALUES (?,?)", new String[]{"name"});
However, I have not found any method to get the returned values from preparedStatement after it is run. I have tried preparedStatemet.getGeneratedKeys();
but it only returns the primary key values.
Upvotes: 0
Views: 884
Reputation: 340118
Use the generated keys to find the inserted rows. In that query return any column you desire.
Stay within a single transaction to get unchanging results.
Upvotes: 1