简体   繁体   English

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

[英]Data truncation:Truncated incorrect Double value

Trying to update an record that I search for in a database, I then try to change an value and click the update button but I keep getting this error of尝试更新我在数据库中搜索的记录,然后尝试更改值并单击更新按钮,但我不断收到此错误

"com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'sdjajsdaj@gmail.com'" “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();
    }

}                                     

Your numberinhg is off您的 numberinhg 已关闭

You defined your email text as id您将 email 文本定义为 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();

Your query isn't matching the ordering of how you're setting data for the statement.您的查询与您为语句设置数据的顺序不匹配。

Your query should look like this:您的查询应如下所示:

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

You are setting the studentId parameter at index 1 but your ?您在索引 1 处设置studentId参数,但是您的? placeholder for studentId is the last one in your query. studentId的占位符是查询中的最后一个。

Index for prepared statement set incorrectly.准备好的语句的索引设置不正确。

    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()));
String sql= "update  studentinfo set Fname = ?,Lname = ?,gender = ?,age = ?, CNumber = ?,email = ? where studentId =  '"+Integer.parseInt(sidTxt.getText())+"' ";  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM