[英]Data truncation:Truncated incorrect Double value
尝试更新我在数据库中搜索的记录,然后尝试更改值并单击更新按钮,但我不断收到此错误
“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();
}
}
您的 numberinhg 已关闭
您将 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();
您的查询与您为语句设置数据的顺序不匹配。
您的查询应如下所示:
String sql= "update studentinfo where studentId = ? set Fname = ?,Lname = ?,gender = ?,age = ?, CNumber = ?,email = ?"
您在索引 1 处设置studentId
参数,但是您的?
studentId
的占位符是查询中的最后一个。
准备好的语句的索引设置不正确。
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.