数据截断:截断不正确的Double值

时间:2020-05-21 14:09:17

标签: java mysql prepared-statement

尝试更新我在数据库中搜索的记录,然后尝试更改一个值并单击“更新”按钮,但此错误不断出现

“ com.mysql.cj.jdbc.exceptions.MysqlDataTruncation:数据截断:截断了不正确的DOUBLE值:'sdjajsdaj@gmail.com'”

   private void upbtnActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    Connection conn=null;
    try{
        Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
        conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/students", "root","Splash7727#" );
        String sql= "update  studentinfo set Fname = ?,Lname = ?,gender = ?,age = ?, CNumber = ?,email = ? where studentId = ?";
        PreparedStatement  pst=conn.prepareStatement(sql); 
        pst.setInt(1,Integer.parseInt(sidTxt.getText()));
        pst.setString(2,FnameTxt.getText());
        pst.setString(3, LnameTxt.getText());
        pst.setString(4, genTxt.getText());
        pst.setString(5, ageTxt.getText());
        pst.setString(6, cnmTxt.getText());
        pst.setString(7,emlTxt.getText());
        pst.executeUpdate();
        JOptionPane.showMessageDialog(this, "Record Updated");
        conn.close();
    }catch(Exception e)
    {
        e.printStackTrace();
    }

}                                     

3 个答案:

答案 0 :(得分:1)

您的电话号码已关闭

您将电子邮件文本定义为id

    pst.setInt(7,Integer.parseInt(sidTxt.getText()));
    pst.setString(1,FnameTxt.getText());
    pst.setString(2, LnameTxt.getText());
    pst.setString(3, genTxt.getText());
    pst.setString(4, ageTxt.getText());
    pst.setString(5, cnmTxt.getText());
    pst.setString(6,emlTxt.getText());
    pst.executeUpdate();

答案 1 :(得分:1)

您的查询与设置语句数据的顺序不匹配。

您的查询应如下所示:

String sql= "update studentinfo where studentId = ? set Fname = ?,Lname = ?,gender = ?,age = ?, CNumber = ?,email = ?"

您要在索引1处设置studentId参数,但是?的{​​{1}}占位符是查询中的最后一个。

答案 2 :(得分:1)

准备好的语句的索引设置不正确。

    pst.setString(1,FnameTxt.getText());
    pst.setString(2, LnameTxt.getText());
    pst.setString(3, genTxt.getText());
    pst.setString(4, ageTxt.getText());
    pst.setString(5, cnmTxt.getText());
    pst.setString(6,emlTxt.getText());
    pst.setInt(7,Integer.parseInt(sidTxt.getText()));
相关问题