Java mySql表中错误列中更新的值

Java mySql表中错误列中更新的值,java,mysql,jsp,Java,Mysql,Jsp,以下是我在jsp页面中的代码:AdminModifyGrocery3.jsp: int g_id = session.getAttribute("g_id") != null ? ((Integer) session.getAttribute("g_id")).intValue() : 0 ; String g_name=(String)request.getParameter("g_name"); String g_price_string=(String)request.getParamet

以下是我在jsp页面中的代码:AdminModifyGrocery3.jsp:

int g_id = session.getAttribute("g_id") != null ? ((Integer) session.getAttribute("g_id")).intValue() : 0 ;
String g_name=(String)request.getParameter("g_name");
String g_price_string=(String)request.getParameter("g_price");  
int g_price = Integer.parseInt(g_price_string);

PreparedStatement stmtUpdate = null;
String strUpdate = "update ShopSystem.Grocery set g_name= ? where g_id = ?";
stmtUpdate = con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_name);
stmtUpdate.setInt(2,g_id);
int c2 = stmtUpdate.executeUpdate();

PreparedStatement stmtUpdate1 = null;
String strUpdate1 = "update ShopSystem.Grocery set g_price=? where g_id=?";
stmtUpdate1 = con.prepareStatement(strUpdate);
stmtUpdate1.setInt(1,g_price);
stmtUpdate1.setInt(2,g_id);
int c1 = stmtUpdate1.executeUpdate();

if(c2>0 && c1>0)
{
    %> 
    <br> Data is modified successfully.<br>
    <% 
}
else
{
    %> 
    <br> Sorry the action cannot be completed.<br> 
    <%  
}
int g_id=session.getAttribute(“g_id”)!=无效的((整数)session.getAttribute(“g_id”)).intValue():0;
String g_name=(String)request.getParameter(“g_name”);
字符串g_price_String=(String)request.getParameter(“g_price”);
int g_price=Integer.parseInt(g_price_字符串);
PreparedStatement stmtUpdate=null;
String strUpdate=“updateshopsystem.grovery set g_name=?其中g_id=?”;
stmtUpdate=con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_名称);
stmtUpdate.setInt(2,g_id);
int c2=stmtUpdate.executeUpdate();
PreparedStatement stmtUpdate1=null;
String strUpdate1=“updateshopsystem.grovery set g_price=?其中g_id=?”;
stmtUpdate1=con.prepareStatement(strUpdate);
stmtUpdate1.setInt(1,g_价格);
stmtUpdate1.setInt(2,g_id);
int c1=stmtUpdate1.executeUpdate();
如果(c2>0&&c1>0)
{
%> 

数据修改成功。

很抱歉,操作无法完成。

使用变量时出现错误:

String strUpdate1 = "update ShopSystem.Grocery set g_price=? where g_id=?";
stmtUpdate1 = con.prepareStatement(strUpdate);
                                       ^^^^^^
stmtUpdate1.setInt(1,g_price);
stmtUpdate1.setInt(2,g_id);
您必须在标记位置使用
strUpdate1

或者您可以使用on语句:

String strUpdate = "update ShopSystem.Grocery set g_name= ?, g_price=?   where g_id = ?";
stmtUpdate = con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_name);
stmtUpdate.setString(2,g_price);
stmtUpdate.setInt(3,g_id);
int c2 = stmtUpdate.executeUpdate();

并删除第二条语句。

此处使用变量时出现错误:

String strUpdate1 = "update ShopSystem.Grocery set g_price=? where g_id=?";
stmtUpdate1 = con.prepareStatement(strUpdate);
                                       ^^^^^^
stmtUpdate1.setInt(1,g_price);
stmtUpdate1.setInt(2,g_id);
您必须在标记位置使用
strUpdate1

或者您可以使用on语句:

String strUpdate = "update ShopSystem.Grocery set g_name= ?, g_price=?   where g_id = ?";
stmtUpdate = con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_name);
stmtUpdate.setString(2,g_price);
stmtUpdate.setInt(3,g_id);
int c2 = stmtUpdate.executeUpdate();

并删除第二条语句。

此处使用变量时出现错误:

String strUpdate1 = "update ShopSystem.Grocery set g_price=? where g_id=?";
stmtUpdate1 = con.prepareStatement(strUpdate);
                                       ^^^^^^
stmtUpdate1.setInt(1,g_price);
stmtUpdate1.setInt(2,g_id);
您必须在标记位置使用
strUpdate1

或者您可以使用on语句:

String strUpdate = "update ShopSystem.Grocery set g_name= ?, g_price=?   where g_id = ?";
stmtUpdate = con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_name);
stmtUpdate.setString(2,g_price);
stmtUpdate.setInt(3,g_id);
int c2 = stmtUpdate.executeUpdate();

并删除第二条语句。

此处使用变量时出现错误:

String strUpdate1 = "update ShopSystem.Grocery set g_price=? where g_id=?";
stmtUpdate1 = con.prepareStatement(strUpdate);
                                       ^^^^^^
stmtUpdate1.setInt(1,g_price);
stmtUpdate1.setInt(2,g_id);
您必须在标记位置使用
strUpdate1

或者您可以使用on语句:

String strUpdate = "update ShopSystem.Grocery set g_name= ?, g_price=?   where g_id = ?";
stmtUpdate = con.prepareStatement(strUpdate);
stmtUpdate.setString(1,g_name);
stmtUpdate.setString(2,g_price);
stmtUpdate.setInt(3,g_id);
int c2 = stmtUpdate.executeUpdate();

然后删除第二条语句。

您应该发布您的数据库架构。您真的认为使用两条更新语句而不是一条更新语句是有效的吗?您必须向uos显示架构定义(创建表语句)。表名:GERRY;列:g_id:Int(11);g_名称:varchar(45);g_价格:Int(11)您应该发布您的数据库架构。您真的认为使用两个更新语句而不是一个更新语句是有效的吗?您必须向uos显示架构定义(创建表语句)。表名:GERRY;列:g_id:Int(11);g_名称:varchar(45);g_价格:Int(11)您应该发布您的数据库架构。您真的认为使用两个更新语句而不是一个更新语句是有效的吗?您必须向uos显示架构定义(创建表语句)。表名:GERRY;列:g_id:Int(11);g_名称:varchar(45);g_价格:Int(11)您应该发布您的数据库架构。您真的认为使用两个更新语句而不是一个更新语句是有效的吗?您必须向uos显示架构定义(创建表语句)。表名:GERRY;列:g_id:Int(11);g_名称:varchar(45);g_价格:Int(11)