如何在长号上运行查询

时间:2015-01-12 19:40:57

标签: java swing odbc

大家好我想尝试对我已经尝试的长号运行一个简单的查询,但仍然返回我id类型是长整数。我得到的所有数据都是jTable,而第一列是id,当我点击它总是给我这个例外时,我在控制台中打印时从表中得到了正确的值

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.

我的代码是:

int row = recordsTable.getSelectedRow();
    String tableValue = (recordsTable.getModel().getValueAt(row, 0).toString());

    String qry = "Select * from records where id ='" + Long.parseLong(tableValue) + "'";
    try {
        db.setStmt((Statement) db.getCon().createStatement());
        ResultSet rs = ((java.sql.Statement) db.getStmt()).executeQuery(qry);
        if (rs.next()) {

            id=rs.getLong("id");
            idTextField.setText(Long.toString(id));


            customerCode = rs.getString("customer_code");
            custCodeTextField.setText(customerCode);

            firstName = rs.getString("first_name");
            firstTextField.setText(firstName);

            lastName = rs.getString("last_name");
            lastTextField.setText(lastName);

            customerContact = rs.getString("customer_mobile");
            custMobTextField.setText(customerContact);

            customerAddress = rs.getString("customer_address");
            custAddressTextField.setText(customerAddress);

            fillComboBox();
            area=rs.getString("area");
            areaComboBox.setSelectedItem(area);

            payment_this_month = rs.getInt("payment");
            paymentTextField.setText(Integer.toString(payment_this_month));

            duePayment = rs.getInt("balance");
            balTextField.setText(Integer.toString(duePayment));

            java.util.Date dateSet = rs.getDate("bill_issued_on");

            billTextField.setText(dateSet.toString());

            connectionStatus = rs.getString("connection_status");
            jComboBox2.setSelectedItem(connectionStatus);

1 个答案:

答案 0 :(得分:1)

删除周围的单引号 '" + Long.parseLong(tableValue) + "'"