字段列表中夹克中的未知列

问题描述 投票:0回答:2

我一直在尝试向名为 bill_items 的表添加值,这是“添加到购物车”按钮的编码,但它显示错误“字段列表中的未知列 Jacket。此编码有什么问题?”

try { rs = stmt.executeQuery("select * from mens_wear where Item_code = 1090;"); while(rs.next()){ icode = rs.getInt("Item_code"); p = rs.getInt("Price"); bname = rs.getString("Brand_Name"); iname = rs.getString("Item_Name"); t = rs.getString("Type"); } rs.close(); stmt.close(); con.close(); } catch(Exception e) {JOptionPane.showMessageDialog(null,e.getMessage());} try { Class.forName("java.sql.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost/aashita","root","1510"); stmt = con.createStatement(); int a = stmt.executeUpdate("insert into bill_items values('"+icode+"','"+t+"','"+bname+"','"+iname+"','"+p+"');"); JOptionPane.showMessageDialog(null,"Added Successfully"); } catch(Exception e) { JOptionPane.showMessageDialog(null,e.getMessage()); } }
    
java mysql jdbc
2个回答
0
投票
在插入中不指定列名称并依赖于表列顺序是一种不好的做法。如果您的任何值包含引号,则也可能存在转义查询字符串的问题。我会尝试添加列名称并使用带参数的准备好的语句。

string updateText = "insert into bill_items (Item_code, Type, Brand_Name, Item_Name, Price) "; updateText += "values (?, ?, ?, ?, ?)"; PreparedStatement stmt = con.prepareStatement(updateText); stmt.setInt(1, icode); stmt.setString(2, t); stmt.setString(3, bname); stmt.setString(4, iname); stmt.setInt(5, p); int a = stmt.executeUpdate();
    

-1
投票
我想开一家像这样的商店

heatedjackets store任何人请告诉我如何开这种类型的商店

© www.soinside.com 2019 - 2024. All rights reserved.