java.sql.SQLSyntaxErrorException:SQL语法中有错误;

时间:2017-04-12 06:27:35

标签: mysql sql netbeans

  

错误:java.sql.SQLSyntaxErrorException:您的SQL中有错误   句法;查看与MySQL服务器版本对应的手册   正确的语法使用near&dc; dc,customerdata cd WHERE   dc.location =' 2' AND cd.username =' jasmin"在第1行

    String dressLoc = dressno;
    String nameRenter = jLabel1.getText();

    String sql = "INSERT INTO orderdata (dressname,price,currentrenter,stat"
            + ",datereserve) SELECT dressname, price, concat(concat(fname,"
            + "' '), lname)AS currentrenter, 'Reserve', CURRENT_TIMESTAMP" 
            + "FROM dresscatalog dc, customerdata cd WHERE dc.location = ? "
            + "AND cd.username = ?";
    try
    {
        pst=conn.prepareStatement(sql);
        pst.setString(1,dressLoc);
        pst.setString(2,nameRenter);
        pst.executeUpdate();


    }
    catch(SQLException ex)
    {
        JOptionPane.showMessageDialog(this, ex);
    }

1 个答案:

答案 0 :(得分:0)

您错过了CURRENT_TIMESTAMPFROM

之间的空白
 + "' '), lname)AS currentrenter, 'Reserve', CURRENT_TIMESTAMP " 
        + "FROM dresscatalog 

我猜你错过了加入条件。在片刻,你得到了一个carthesian产品