aspose file tools*
The moose likes JDBC and the fly likes Multiple insert into database 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 "Multiple insert into database" Watch "Multiple insert into database" New topic
Author

Multiple insert into database

Raghav
Greenhorn

Joined: Jul 24, 2001
Posts: 14
Hi,
I am trying to insert multiple values into multiple tables at a single instance.I have a HTML form and Servelt that connects me to the MSAccess database . i have 4 different tables in the database.and i want to enter the values in the form to these tables in a single submit button click. i tried doing
Statement st = conn.createStatement();
st.addBatch("insert into table 1");
st.addBatch("insert into table 2");
st.addBatch("insert into table 3");
st.addBatch("insert into table 4");
int [] count = st.executeBatch();
but i am getting a error all the time i do it this way , is this any other way to carry out this type of operation.
thanks
raghav

Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
Originally posted by Raghav Subramanian:
Hi,
I am trying to insert multiple values into multiple tables at a single instance.I have a HTML form and Servelt that connects me to the MSAccess database . i have 4 different tables in the database.and i want to enter the values in the form to these tables in a single submit button click. i tried doing
Statement st = conn.createStatement();
st.addBatch("insert into table 1");
st.addBatch("insert into table 2");
st.addBatch("insert into table 3");
st.addBatch("insert into table 4");
int [] count = st.executeBatch();
but i am getting a error all the time i do it this way , is this any other way to carry out this type of operation.
thanks
raghav

Raghav, What error are you getting? You could do this without a batch statement. Disable autocommit, do all the inserts, and then do an explicit commit. You may need to do this if your driver does not support batch statements (which I do not think the JDBC-ODBC bridge does).
Robert
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Order of the inserts may also matter. If the tables have relationships, then you must enter them in a fashion that you do not violate key constraints and so on. If you post the error message, it might be easier for us to help you.
Jamie
[This message has been edited by Jamie Robertson (edited August 15, 2001).]
 
 
subject: Multiple insert into database