wood burning stoves*
The moose likes JDBC and the fly likes ArrayList to JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ArrayList to JDBC" Watch "ArrayList to JDBC" New topic
Author

ArrayList to JDBC

david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 75
Hi All trying to get this code working,

I have some code that i wish to place the ArrayList into a Database Table



I am getting the Following Errors
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:497)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

Well, yeah. An INSERT statement doesn't return a ResultSet, so writing code which acts as if it does is an error. So the method you want to use isn't executeQuery (which returns a ResultSet), but something else which you should be able to find very quickly by consulting the API documentation.

You seem to have mixed up your original requirements (Write the entries of a List into a database table) with some code which reads those entries from a database table into a List.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 75
Have you got a link to the API doc with this information would help a lot .
bala nannaka
Ranch Hand

Joined: Apr 02, 2007
Posts: 49
Try to use the executeUpdate which returns an int value pointing to number of rows effected with your statement. Generally for all INSERT,UPDATE and DELETE operations we can use executeUpdate which they don't return any result set but the number of rows affected with those operations.
david foley
Ranch Hand

Joined: Dec 01, 2012
Posts: 75
bala nannaka wrote:Try to use the executeUpdate which returns an int value pointing to number of rows effected with your statement. Generally for all INSERT,UPDATE and DELETE operations we can use executeUpdate which they don't return any result set but the number of rows affected with those operations.



OK..

I have INSERT, UPDATE, DELETE on the Database, I am able to Save the Database using Serialization but am looking for a Way to Drop Everything inside the Database and Reload the database with the saved information that is inside the Array List or the Serialized File.
 
Don't get me started about those stupid light bulbs.
 
subject: ArrayList to JDBC