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);


}