dbconn.executeUpdate("intset into on_order_iteam(orderid,commodityid,commoditynumber,comm_price,status,username)values("+id+","+(Integer.parseInt(a[i][0]))+","+(Integer.parseInt(a[i][1]))+","+(Float.parseFloat(a[i][2]))+",'1','"+a[i][3]+"')");
他提醒我的出错是:An error occurred at line: 41 in the jsp file: /fillorder.jsp
The local variable id may not have been initialized
他提醒我的出错是:An error occurred at line: 41 in the jsp file: /fillorder.jsp
The local variable id may not have been initialized
int id;
if(rs1.next())
{
id=rs1.getInt("id");
}
rs1.close();
String a[][]=new String[100][5];
ResultSet rs=dbconn.executeQuery("select * from on_cart");
int j=0;
while(rs.next())
{
a[j][0]=""+rs.getInt("commodityid");
a[j][1]=""+rs.getInt("commoditynumber");
a[j][2]=""+(rs.getFloat("comm_price")*100);
a[j][3]=rs.getString("username");
j++;
}
rs.close();
int i=j-1;
while(i<-1)
{
dbconn.executeUpdate("intset into on_order_iteam(orderid,commodityid,commoditynumber,comm_price,status,username)values("+id+","+(Integer.parseInt(a[i][0]))+","+(Integer.parseInt(a[i][1]))+","+(Float.parseFloat(a[i][2]))+",'1','"+a[i][3]+"')");
i=i-1;
}
dbconn.executeUpdate("delete from on_cart where username='"+a[0][3]+"'");
dbconn.close();
response.sendRedirect("orderlist.jsp");这是完整的啊..大家帮忙看看ID为什么没有值啊
----------------------------------------------------------
An error occurred at line: 41 in the jsp file: /fillorder.jsp
The local variable id may not have been initialized
-------------------------------------------------------------你肯定在fillorder.jsp文件中定义了一个变量id;
你定义的时候没有对其赋初值,JAVA是强类型语言,所以在编译的时候就报错了.
if(rs1.next())
{
id=rs1.getInt("id");
}
rs1.close();