aspose file tools*
The moose likes JDBC and the fly likes how to do multiple insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to do multiple insert" Watch "how to do multiple insert" New topic
Author

how to do multiple insert

Deepthi Xavy
Ranch Hand

Joined: Aug 31, 2009
Posts: 32
Hai friends,

I need a sample querry,for inserting bulk datas at a time..for Example if there are 200 records,without using looping concept,how to do insert all the records in mysql server..can any one help me out for this...
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Deepthi Xavy wrote:for Example if there are 200 records,without using looping concept,how to do insert all the records in mysql server..

Why do you want to write down 200 SQL statement, if looping will make it in simple 2 line of code ?

Still, the JDBC Batch Updates will help
OR
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec2/jdbc2.1.frame6.html


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
avijit majumder
Greenhorn

Joined: Sep 01, 2009
Posts: 15

String s1="insert into table values('10','a');
String s2="insert into table values('2','b');
String s3="insert into table values('3','c');
con=com...
java.sql.Statement stmt=con.createStatement();
stmt.addBatch(s1);
stmt.addBatch(s2);
stmt.addBatch(s3);
int[] inserts = stmt.executeBatch();
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
String formatter is your best bet to save effort. Looping and batch statements are a boon, use them.


Experience and talent are independent of age
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9618
    
    2

You can also handle them using control files. I'm not sure if MySQL has such a thing, but I've done that using Oracle.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Jothi Shankar Kumar wrote:You can also handle them using control files. I'm not sure if MySQL has such a thing, but I've done that using Oracle.

You mean to say the sqlldr facility given by Oracle, using control, data and log files!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9618
    
    2

Yes, exactly!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to do multiple insert