-
null exception error
hey..
actually i have 19 rows...but sometime i have to insert only two rows values..then null exception error will come...
when i insert the 19 rows values it successfully insert the values in database...and displays values on page..
what now i have to do....
because sometime i have to enter only two rows values...sometimes 5 rows values...
plz give me ur help in this...
my code is as follows:
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO gl_mast VALUES (?, ?, ?, ?, ?, ?)");
for(int i=1; i < 20; i++) {
int Code=Integer.parseInt(request.getParameter((i==1)?"code" "code_" +i)));
pstmt.setInt(1,Code);
String Description=request.getParameter((i==1)?"Description" "Description_" +i));
pstmt.setString(2,Description);
float Dr_Amt =Float.parseFloat(request.getParameter((i==1)?"DrAmount" "DrAmount_" +i)));
pstmt.setFloat(3,Dr_Amt );
float Cr_Amt =Float.parseFloat(request.getParameter((i==1)?"CrAmount" "CrAmount_" +i)));
pstmt.setFloat(4,Cr_Amt);
String Type =request.getParameter((i==1)?"type" "type_" +i));
pstmt.setString(5,Type );
float Pct =Float.parseFloat(request.getParameter((i==1)?"pct" "pct_" +i)));
pstmt.setFloat(6,Pct);
pstmt.addBatch();
conn.commit();
conn.setAutoCommit(true);
}
-
I'm not heavily into db programming nowadays, so that may be why I cant see the reason for messing with the connection's commit mode here. If its a standard java.sql.Connection interface it should be autocommit by default. Have you tried leaving that out, skip the addBatch() and just do a plain execute of the prepared statement ?
eschew obfuscation
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks