This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

how to do multiple insert  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 2908
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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();
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String formatter is your best bet to save effort. Looping and batch statements are a boon, use them.
 
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, exactly!
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!