当我单击按钮时,我试图让代码运行,但是它告诉我我需要捕获异常,但我认为我已经做到了。我错过了什么吗?这似乎很简单,但我似乎无法弄清楚。我在第 76-83 行收到此错误
class EmpList {
private static JFrame frame;
private static JTextField textField;
public static void main (String args [])
throws SQLException {
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
final String user, pass, query;
user = "asdf";
pass = "asdf";
query = "select * from customers";
try
{
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@Picard2:1521:itec2",user,pass);
final Statement stmt = conn.createStatement ();
final ResultSet rset = stmt.executeQuery (query);
EmpList window = new EmpList();
frame = new JFrame();
frame.setBounds(100, 100, 630, 470);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
final JTextArea textArea = new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setBounds(10, 179, 594, 241);
frame.getContentPane().add(textArea);
textField = new JTextField();
textField.setBounds(255, 69, 86, 20);
frame.getContentPane().add(textField);
textField.setColumns(10);
JLabel lblEnterCustomerId = new JLabel("Enter Customer ID (1-6)");
lblEnterCustomerId.setBounds(240, 43, 153, 14);
frame.getContentPane().add(lblEnterCustomerId);
JButton btnGetInfo = new JButton("Get Info");
btnGetInfo.setBounds(255, 115, 89, 23);
frame.getContentPane().add(btnGetInfo);
btnGetInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
while (rset.next ())
{
textArea.append((rset.getString("CUSTID") + " - " + rset.getString("CUSTSSN")
+ " - " + rset.getString("LNAME") + " - " + rset.getString("FNAME") + " - " +
rset.getString("STREET") + " - " + rset.getString("CITY") + " - " + rset.getString("STATE") +
" - " + rset.getString("ZIP") + " - " + rset.getString("PHONE") + System.getProperty("line.separator")
+ System.getProperty("line.separator")));
}
}
});
window.frame.setVisible(true);
}
我认为这会捕获异常,但我想它不会。
catch (SQLException e)
{
System.out.println ("Could not load the db"+e);
}
}
}