NetBeans에서이 메서드에서 SQLException을 throw해야한다는 오류가 발생합니다.Java - 예외를 throw해야하지만 어떻게해야합니까?
private void displayCustomerInfo(java.awt.event.ActionEvent evt)
{
int custID = Integer.parseInt(customerID.getText());
String info = getCustomerInfo(custID);
results.setText(info);
}
이 메서드는 NetBeans에서 만들어 지므로 서명을 편집하고 예외를 throw 할 수 없습니다. 그래서 getCustomerInfo()
메서드를 만들었습니다. 이 메서드는 고객에 대한 데이터베이스에서 정보를 검색하는 메서드를 사용하므로 예외가 throw됩니다.
public String getCustomerInfo(int cid) throws SQLException
{
Customer c = proc.getCustomer(cid);
// get info
return "info";
}
getCustomer
메소드도 예외를 발생시키고 proc.java는 컴파일됩니다.
정확한 오류는
unreported exception java.sql.SQLException; must be caught or declared to be thrown
입니다.
는 용서하지만, 왜 모든 사람들이 이야기 * 단지 *에 대한 시도 - 캐치 여기에? 그것은 옵션이지만, 유일한 옵션은 아닙니다. 예외가 던져 질 수없는 이유는 무엇입니까? 왜 netbeans가 허용하지 않습니까? Netbeans (이클립스 사용)을 사용하지 않지만 IDE가 생성 된 코드를 변경할 수 없다는 것은 바보 같은 소리입니다. – Nivas