【问题标题】:Cant update my database无法更新我的数据库
【发布时间】:2015-08-22 20:47:17
【问题描述】:

我无法使用从我的文本字段中转到我的数据库的值来更新我的数据库我没有异常错误但没有任何反应

private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
    row = table.getSelectedRow();
    int column = table.getColumnCount();

    try {
        Conn();
        System.out.print(table.getValueAt(row,0));
        pStmt = conn.prepareStatement("update customer_tbl set LName = '" + txtLname.getText() + "', FName= '" 
            + txtFname.getText() + "', Address = '" + txtAddress.getText() + "', ContactNumber = '"+txtContact.getText() 
            + "', Age = '" + txtAge+"' WHERE Name_ID = '" + table.getValueAt(row,0) + "'");

        //  st = conn.createStatement();
        // rs = st.executeQuery("UPDATE customer_tbl SET Fname = '"+txtFname.getText()+"' Lname= '"+txtLname.getText()+"', Age = '"+txtAge.getText()+"', Address = '"+txtAddress.getText()+"', ContactNumber = '"+txtContact+"' WHERE Customer_id = '"+ table.getValueAt(row,0)+"'");
        pStmt.executeUpdate();

        JOptionPane.showMessageDialog(null,"Update success !");

        //FillList();
    }

【问题讨论】:

  • catch(...) {...} 块中有什么内容?
  • com.mysql.jdbc.MysqlDataTruncation 先生出现异常:数据截断:第 1 行的“年龄”列的数据太长
  • ???在您的问题中,尽管您声明了" i have no exceptions error...",所以您在上面的陈述"got an exception" 让我很困惑。是哪个?
  • 您最近删除了 your question on isSelectRow 却没有得到答复,也没有让我们知道出了什么问题,那么您问了这个问题,这对异常与无异常没有意义(是不是您没有发现异常?)....

标签: java database textfield


【解决方案1】:

对不起,我得到了答案。我将Age = txtAge 设置为txtAge.getText()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多