Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unreported exception; java.sql.SQLException; must be caught or declared to

807603Feb 9 2008 — edited Feb 9 2008
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 8 2008
Added on Feb 9 2008
1 comment
3,789 views