• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem connecting with the database

 
krishi Bhas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34668
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krishi,
Is oracle12.zip in your classpath?
 
krishi Bhas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, how do i set the classpath for oracle12.zip
 
krishi Bhas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are not errors while running, these are errors while compiling. If a method throws an Exception you must catch it or throw it further on.

 
krishi Bhas
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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="jdbcdbc: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();}
}
}
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This error sounds like you are using the command

java Jdbc.java

instead of using

java Jdbc

Exception in thread "main" java.lang.NoClassDefFoundError: Jdbc/java
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic