라디오 버튼을 사용하여 데이터베이스에 항목을 삽입하려는 경우 옵션이 예외를 throw합니다. 비슷한 질문으로 답변을 얻으려고했지만 하나도 얻지 못했습니다.NumberFormatException JTextField 값의 경우
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel2.setVisible(true);
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/test";
Connection conn=DriverManager.getConnection(url,"root","Sumit");
String query="Insert student values(?,?,?)";
PreparedStatement pst=conn.prepareStatement(query);
pst.setString(1, jTextField1.getText());
pst.setString(2, jTextField2.getText());
pst.setInt(3, Integer.parseInt(jTextField3.getText()));
int rec=pst.executeUpdate();
if(rec>0)
{
jLabel6.setText("New Student Added");
jTextField1.setText(" ");
jTextField2.setText(" ");
jTextField3.setText(" ");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
어떤 도움을 크게 감상 할 수 다음과 같이
코드입니다. 내가 찾은 스택 추적을 검사 한 후 오류가 라인에서 아니오를 어디로 jTextField3
에서 정수를 구문 분석 194입니다.
은'jTextField3' 어쩌면이 정수가 아닌의 내용은 무엇입니까 예를
java.lang.NumberFormatException: For input string: "xyz"
을 위해, 어떻게 생겼는지를 알려주는 메시지가 포함? 내 테이블에 – JensjTextfield3 int, 롤 번호가 필요합니다. –
네, 하나 필요합니다. 그러나 숫자가 아닌 값을 삽입하면 이러한 예외가 발생합니다. – Jens