sales是表名,
大虾关注一下,上面语句那些地方要加引号???

解决方案 »

  1.   

    prepareStatement的sql语句里那些变量应该是"?"才对吧
    用createStatement,然后stmt.execute(sql)
      

  2.   

    ("INSERT INTO sales( id£¬prod_id,quantity,price,unit) VALUES('"+theId+"','"+theProd+"','"+theQuantity+"','"+thePrice+"','"+theUnit+"')");
      

  3.   

    你可以将你的SQL语句打出来看看,或者打出来之后在数据库端执行一下试试,如果没问题就OK。
    对于String型的需要在两端家'',假设你的这些字段id为int型,其余都为String型
    pstmt = con.prepareStatement("INSERT INTO sales( id,prod_id,quantity,price,unit) VALUES(" + theId + ",'" + theProd + "','" + theQuantity + "','" + thePrice + "',' + theUnit + "')");
      

  4.   

    String ssql="INSERT INTO sales( id,prod_id,quantity,price,unit) VALUES
    ("
    +theId
    +","
    +theProd+","
    +theQuantity","
    +thePrice","
    +theUnit
    +")"pstmt = con.prepareStatement(ssql);