Click to See Complete Forum and Search --> : null exception error


abhit_kumar
01-04-2005, 07:48 AM
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);


}

ray326
01-04-2005, 10:14 AM
; i < 20; Obviously that's your problem.

abhit_kumar
01-04-2005, 11:10 PM
i < 20;

i know thats the problem..now to solve this problem..what modification has to be made in my code.

help

ray326
01-04-2005, 11:51 PM
public java.util.Map getParameterMap()

Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.

Now you have something you can determine the size of to limit a for loop or you can just iterate the Map.