aspose file tools*
The moose likes JDBC and the fly likes problem connecting with the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem connecting with the database" Watch "problem connecting with the database" New topic
Author

problem connecting with the database

krishi Bhas
Greenhorn

Joined: Dec 18, 2006
Posts: 8
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

Joined: May 26, 2003
Posts: 30955
    
158

Krishi,
Is oracle12.zip in your classpath?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
krishi Bhas
Greenhorn

Joined: Dec 18, 2006
Posts: 8
No, how do i set the classpath for oracle12.zip
krishi Bhas
Greenhorn

Joined: Dec 18, 2006
Posts: 8
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

Joined: Aug 31, 2006
Posts: 226
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

Joined: Dec 18, 2006
Posts: 8
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

Joined: Oct 10, 2000
Posts: 1364
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem connecting with the database