While connecting one applet to an Access DB using the jdbc:ucanaccess method, I get the following error:
Firstdb.java:44: error: unreported exception SQLException;
must be caught or declared to be thrown
stmt.executeUpdate(sql);
^
The code that I used for the applet is as follows (add()
and setBounds()
are removed from init()
):
public class Firstdb extends Applet implements ActionListener {
TextField t1, t2;
Label l1;
Button b1, b2;
Connection con;
Statement stmt;
public void init() {
try {
con = DriverManager.getConnection("jdbc:ucanaccess://H:/test/db.mdb");
stmt = con.createStatement();
} catch (Exception e) {
}
}
public void actionPerformed(ActionEvent ae) {
String sql;
if (ae.getSource() == b1) {
sql = "insert into user (Uname) values(" + t1.getText() + ")";
stmt.executeUpdate(sql);
} else if (ae.getSource() == b2) {
//do something
}
}
}
Note: java version "1.8.0_141"
Why am I getting this error?
}catch(Exception e){ }
to}catch(Exception e){ e.printStackTrace(); }
then copy/paste the resulting output from the Java Console. 2) Why use AWT? See this answer for many good reasons to abandon AWT components in favor of Swing. – Eurus