I am trying to connect to Oracle9i using Type-1 driver(JDBC-ODBC bridge). i have created dsn and when i am trying to run the program i am getting ClassNotFound exception
Jeanne Boyarsky
,
author & internet detective
staff
Jdbc.java:9: unreported exception java.lang.ClassNotFoundException; must be caug ht or declared to be thrown Class.forName(driverclass); ^ Jdbc.java:10: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown Connection conn=DriverManager.getConnection(url,username,password); ^ Jdbc.java:12: unreported exception java.sql.SQLException; must be caught or decl ared to be thrown conn.close(); ^ 3 errors
I know these errors are occuring at compile time..i know how to use try-catch-finally . the problem is..how do i connect to the database.. If i want to connect to oracle 9i or 10g using type1 driver(Microsoft ODBC connection) creating dsn name and trying to connect to the database, the driverclass is not loading and its giving Exception in thread "main" java.lang.NoClassDefFoundError: Jdbc/java
Here is the program: import java.sql.*; public class Jdbc{ public static void main(String args[]) throws Exception{ Connection conn=null; try{ String driverclass="sun.jdbc.odbc.JdbcOdbcDriver"; String url="jdbc:odbc:custdsn"; String username="system"; String password="admin"; Class.forName(driverclass); conn=DriverManager.getConnection(url,username,password); System.out.println("connection established"); } catch(Exception e){e.printStackTrace();} finally{ conn.close();} } }