Forums Register Login

problem connecting with the database

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Krishi,
Is oracle12.zip in your classpath?
+Pie Number of slices to send: Send
No, how do i set the classpath for oracle12.zip
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.

+Pie Number of slices to send: Send
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();}
}
}
+Pie Number of slices to send: Send
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

 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2905 times.
Similar Threads
populating an array via the user
how To connect the mysql database from java with my webserver
How to pass string from TCP server (a Runnable) to main activity (in Android)?
Eclipse + RedHat -> Gtk-warning
question about decompress?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:37:30.