这是代码:

       int value = JOptionPane.showConfirmDialog(Delete_Panel, "Delete Record of '"+rs.getString("Name")+"'", "Delete Now", JOptionPane.YES_NO_OPTION);


它什么也没做..
但是,当我删除rs.getString("Name")时,它可以正常工作,但是我也想在确认对话框中从ms访问中显示该名称,然后根据是,没有选项,我希望执行我的其他代码。

完整的源代码是:

       String input = txtDelete.getText();


        Connection connection;

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection = DriverManager.getConnection("jdbc:odbc:NewPData");
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select ID from Table1 where ID=" + input);

            if (!rs.next()) {
                JOptionPane.showMessageDialog(Delete_Panel, "ID does not exist");
            } else {

             // int value = JOptionPane.showConfirmDialog(Delete_Panel, "Delete Record of '"+rs.getString("Name")+"'", "Delete Now", JOptionPane.YES_NO_OPTION);

                st.executeUpdate("delete from Table1 where ID=" + input);
                JOptionPane.showMessageDialog(Delete_Panel, "Record is Deleted");
                connection.close();

            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
        }
    }

最佳答案

您的代码应该可以正常工作。请在对话框中发布确切的输出。

您是否在尝试调用showConfirmDialog之前先获取数据?

rs = Statement.executeQuery

编辑:

ojit_pre

Will only get the colum ID. Try this:

ResultSet rs = st.executeQuery("select ID from Table1 where ID=" + input);

10-07 14:38