Results 1 to 6 of 6
- 02-11-2013, 01:24 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
- 02-11-2013, 02:02 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How to find multiple inset into database success?
Are you talking a batch job with multiple insert statements?
Please do not ask for code as refusal often offends.
- 02-12-2013, 10:20 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
Re: How to find multiple inset into database success?
Hi
No, i have data in List and loop through this list and insert record into database. Here is my code
String qString = "INSERT INTO Estd_Contents( file_ref, a,b ) values (?,?,?)";
PreparedStatement stmt = conSqlServer.prepareStatement(qString);
for(int i = 0; i < lstAllContents.size(); i++)
{
stmt.setString(1, lstAllContents.get(i).getFileRef());
stmt.setDouble(2, lstAllContents.get(i).getNetAmt());
stmt.setString(3, lstAllContents.get(i).getAcctNo());
stmt.executeUpdate();
}
conSqlServer.commit();
System.out.println("Contents inserted successfully!");
Maximum 3500 records i will insert at a time.
- 02-12-2013, 11:14 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How to find multiple inset into database success?
Batch them, for starters.
Doing single inserts like that is not terribly good performance-wise.
Then you will be able to see how many succeeded, and which ones (depending on db).Java Code:for(int i = 0; i < lstAllContents.size(); i++) { stmt.setString(1, lstAllContents.get(i).getFileRef()); stmt.setDouble(2, lstAllContents.get(i).getNetAmt()); stmt.setString(3, lstAllContents.get(i).getAcctNo()); stmt.addBatch(); } int[] results = stmt.executeBatch();Please do not ask for code as refusal often offends.
- 02-12-2013, 01:39 PM #5
Member
- Join Date
- Feb 2013
- Posts
- 9
- Rep Power
- 0
Re: How to find multiple inset into database success?
Thanks Tolls
it worked. Before it was taking 4 seconds to insert 3500 records and now less than 1 sec
- 02-12-2013, 01:57 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Problem in my OCJP success kit.
By makpandian in forum Java CertificationReplies: 0Last Post: 08-26-2011, 01:56 PM -
Using Linear Search to find multiple indexes
By Roberto1989 in forum New To JavaReplies: 1Last Post: 03-16-2011, 04:36 PM -
Accessing multiple database
By saurabh1989 in forum JDBCReplies: 0Last Post: 02-23-2011, 05:04 PM -
Hibernate with multiple database
By Marty in forum JDBCReplies: 3Last Post: 12-23-2008, 12:57 PM -
How to store Multiple calendars in PIM Database
By thirupathik in forum CDC and Personal ProfileReplies: 0Last Post: 07-13-2008, 01:45 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks