【问题标题】:Data truncation: Truncated incorrect DOUBLE value数据截断:截断不正确的 DOUBLE 值
【发布时间】:2015-08-07 04:38:15
【问题描述】:
// my button
public void actionPerformed(ActionEvent arg0) {               
  String sorgu="UPDATE calisan SET CalisanAdi=? AND CalisanSoyadi=? AND kul_adi=? AND sifre=? WHERE idcalisan=? ";
  DBConnection.KullaniciGuncelle(calisan_ad.getText(), calisan_soyad.getText(),calisan_kul_adi.getText(), calisan_sifre.getText(), sorgu);
}

怎么了?如果我添加列这显示问题

参数索引超出范围(1>参数个数,即0)

public static void KullaniciGuncelle(String ad, String soyad, String kadi, String sifre,String sorgu){

connection();

try
{
    Connection connect = DriverManager.getConnection(host, username , pass);
    PreparedStatement statement = (PreparedStatement) connect.prepareStatement(sorgu);

    statement.setString(1, ad);
    statement.setString(2, soyad);
    statement.setString(3, kadi);
    statement.setString(4, sifre);

    statement.executeUpdate();
    statement.close();
    connect.close();   
}
catch(SQLException e)
{
    e.printStackTrace();  
}

【问题讨论】:

  • update table_name set col1='val1', col2='val2',... where col1='something'
  • 无法判断这里出了什么问题,因为我们不知道您的表中有什么或您调用getText() 的所有这些类。请澄清你的问题。您的查询中还有五个绑定参数?,但只有四个参数加上您正在调用的DbConnection 方法的查询字符串。
  • 如果我使用'参数值问题:S
  • 你觉得这段代码怎么样? DBConnection 这里

标签: java mysql


【解决方案1】:

您只在更新方法中绑定了四个参数。但是您的查询字符串包含五个。此外,您在查询中滥用了AND。

查询应该是这样,删除额外的AND 项。

UPDATE calisan 
   SET CalisanAdi=?, CalisanSoyadi=?,
       kul_adi=?, sifre=?
WHERE idcalisan=? ";

您的更新方法需要为第五个? 额外绑定一个参数。我猜idcalisan 是一个ID(尽管我不懂土耳其语,抱歉)所以我建议setInt()。

    statement.setString(1, ad);
    statement.setString(2, soyad);
    statement.setString(3, kadi);
    statement.setString(4, sifre);
    statement.setInt   (5, idcalisan)

【讨论】:

  • 如果我使用额外的参数,KullaniciGuncelle 方法需要新的文本框。
猜你喜欢
  • 2015-02-23
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多