Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple insert into database

 
Raghav
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic