Here is code:
int value = JOptionPane.showConfirmDialog(Delete_Panel, "Delete Record of '"+rs.getString("Name")+"'", "Delete Now", JOptionPane.YES_NO_OPTION);
It does nothing ..
but when I remove rs.getString("Name") it works perfectly but I also want to show that name from ms access on confirm dialogue and then according to yes no option I want my further code to be executed.
Full Source code is:
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) {
}
}
Your code should work just fine. Please post what was the exact output in the dialog.
Have you tried to fetch the data first before invoking the showConfirmDialog?
rs = Statement.executeQuery
EDIT:
Will only get the colum ID. Try this:
ResultSet rs = st.executeQuery("select ID,Name from Table1 where ID=" + input);