Results 1 to 4 of 4
Thread: count inserted line in database
- 08-16-2010, 10:25 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 6
- Rep Power
- 0
count inserted line in database
Hi all,
need your help..i really new to java..so please guide me.
i wanted to create script that can count how many line inserted in database (sql) every time i run my script..based on my script below,it only printed out 1 line inserted.But when i checked in the database, there are almost 100+ lines inserted..i had tried to do try an error but i couldn't found out the problem..anyone can help me on this?
Java Code:while (result.next()) { pstmt.setString(1, result.getString(1)); pstmt.setString(2, result.getString(2)); pstmt.setString(3, result.getString(3)); pstmt.setString(4, result.getString(4)); pstmt.setString(5, result.getString(5)); pstmt.setString(6, result.getString(6)); pstmt.setString(7, result.getString(7)); pstmt.setString(8, result.getString(8)); pstmt.setString(9, result.getString(9)); pstmt.setString(10, result.getString(10)); pstmt.setString(11, result.getString(11)); pstmt.setString(12, result.getString(12)); pstmt.setString(13, result.getString(13)); pstmt.setString(14, result.getString(14)); pstmt.setString(15, result.getString(15)); pstmt.setString(16, result.getString(16)); pstmt.setString(17, result.getString(17)); pstmt.setString(18, result.getString(18)); pstmt.setString(19, result.getString(19)); pstmt.setTimestamp(20, result.getTimestamp(20)); pstmt.setTimestamp(21, result.getTimestamp(21)); pstmt.executeUpdate(); } int rows = 0; rows = pstmt.executeUpdate(); connOracle.commit(); System.out.printf("%d row(s) inserted!",rows); System.out.println(" "); System.out.println("Done");
- 08-16-2010, 10:46 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 08-16-2010, 10:49 AM #3
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Hi,
From your code I assume that you want to do an insert or update into a table from a result of another query.
In the while loop you call the executeUpdate method. This method returns number of rows affected by the query. Then you need to increment the total rows affected in the while loop.
Instead of executing every single statement you can do a batch insert or update.Java Code:int totalRows = 0; while (rs.next()) { .... .... int rows = pstmt.executeUpdate(); totalRows = totalRows + rows; } System.out.println("Rows inserted: " + totalRows);Website: Learn Java by Examples
- 08-16-2010, 10:57 AM #4
Similar Threads
-
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
How to Update newly inserted rows in the Excel through Java..Pls help..Explained well
By josephkarthic in forum New To JavaReplies: 2Last Post: 03-16-2010, 08:24 PM -
Line Count
By tim in forum NetBeansReplies: 1Last Post: 08-02-2009, 04:41 PM -
count occurence of word in a line of text
By sinyi88 in forum New To JavaReplies: 19Last Post: 02-28-2009, 07:37 AM -
Preventing inserted text from becoming colored from previous style
By jkhoa in forum AWT / SwingReplies: 2Last Post: 08-10-2007, 12:36 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks