0
삭제 버튼에 문제가 있습니다. 텍스트 필드에 아무것도 입력하지 않고 삭제 버튼을 누르면 팝업 메뉴가 예외로 표시되지 않습니다.사용자로부터 빈 입력을 감지하지 못하는 코드
private void billdeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
int id=Integer.parseInt(billidtext.getText());
try (//step2 create the connection object
Connection con = DriverManager.getConnection("jdbc:oracle:thin:localhost:xe","hr","****")) {
Statement stmt=con.createStatement();
stmt = con.createStatement();
String sql = "DELETE FROM bill " +
"WHERE bid = ('"+id+"')";
int w=stmt.executeUpdate(sql);
if(w!=0)
JOptionPane.showMessageDialog(null,"Deleted Successfully!"); //this is displayed successfully
else
JOptionPane.showMessageDialog(null,"value does not exists!");// this is displayed successfully
supplieridtext.setText("");
//view trigger
String sql1="SELECT * FROM bill";
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql1);
//STEP 5: Extract data from result set
billtable.setModel(DbUtils.resultSetToTableModel(rs));
rs.close();
//step5 close the connection object
}
}catch(ClassNotFoundException | SQLException e){
JOptionPane.showMessageDialog(null,"no value entered!");} //this line is not displayed when the text field is empty
}
'Integer.parseInt'가 이해할 수없는 입력이 주어진 경우에 대비해서'java.lang.NumberFormatException'을 잡아야하는 것처럼 보입니다. –
'billidtext.getText(). trim(). isEmpty()' – MadProgrammer