Hi everyone,
For my Java course assignment we need to make a small application that uses a MS Access database. But de code below gives me a "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error.
public class ConnectieBeheer
{
private static Connection con;
private static Statement stmt;
private static ResultSet res;
private static ResultSetMetaData md;
private ConnectieBeheer(){}
public static void openDB() {
Driver driver = new JdbcOdbcDriver();
Properties info = new Properties();
String url = "jdbc:odbc:theater";
con = driver.connect(url, info); <--- Error here
if (con != null)
{
stmt = con.createStatement(); <--- Error here
DatabaseMetaData dma = con.getMetaData(); <--- Error here
}
}
So I tried this :
public static void openDB() throws SQLException {
Now I do not get an error.
The OpenDB method is called from a different class like this :
public static void test1(){
ConnectieBeheer.openDB();
System.out.println("DB opened");
}
But now it gives the same "Unreported exception; java.sql.SQLException; must be caught or declared to be thrown at line xx" error but now at the line ConnectieBeheer.openDB();
Why is this? And what can I do to correct this?
Thanks!
Steven.