| | |
Connect java to oracle
![]() |
•
•
Join Date: Jun 2009
Posts: 9
Reputation:
Solved Threads: 0
Hi guys
Iwant to connect java to oracle ,but Iam not familiarneither jdbc nor in setting classpath
however depending on my little information,I used the following code
then I run the followin commands into dos command
but I get the error:-
Exception in thread "main" java.lang.NoClassDefFoundError: c:\OraThin
Iwould be glad if someone help me.
Iwant to connect java to oracle ,but Iam not familiarneither jdbc nor in setting classpath
however depending on my little information,I used the following code
java Syntax (Toggle Plain Text)
import java.sql.*; public class OraThin { public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("oracle.jdbc.driver.OracleDriver"); // // or // DriverManager.registerDriver // (new oracle.jdbc.driver.OracleDriver()); String url = "jdbc:oracle:thin:@computer-d219bd:1521:orcl"; Connection conn = DriverManager.getConnection(url,"system", "overmars11"); conn.setAutoCommit(false); Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION"); while (rset.next()) { System.out.println (rset.getString(1)); } stmt.close(); System.out.println ("Ok."); } }
Java Syntax (Toggle Plain Text)
C:\j2sdk1.4.1\bin>javac -classpath d:\oracle\product\10.2.0\db1\jdbc\lib c:\OraThin.java C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib c:\OraThin
Exception in thread "main" java.lang.NoClassDefFoundError: c:\OraThin
Iwould be glad if someone help me.
Last edited by vanpersie; Jun 15th, 2009 at 9:52 pm.
Your have to set environment variable PATH with "C:\j2sdk1.4.1\bin>".
However you may run this program.
However you may run this program.
Java Syntax (Toggle Plain Text)
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib;c:\; OraThin
Failure is not fatal, but failure to change might be. - John Wooden
The problem is not of PATH variables or the Oracle driver Jar not found in classpath, It is quite simply you are not invoking the program correctly.
When you are running any Java program, you give the "java" interpreter only the name of the main class (and quite obviously there is no main class by the name of C:\OraThin) .
Also in your case the complication rises cause you are specifying the value for your "classpath", here along with your other JARs you would also need to include the directory which contains the class file of your OraThin class ( which is what adatapost has done by including "c:" in the classpath as shown here
You should try what adatapost has suggested, I ended up giving him a bad cookie cause I failed to observe you are running your programs from inside the bin directory of your JDK installation. Hopefully someone will equalize for my blunder there.
When you are running any Java program, you give the "java" interpreter only the name of the main class (and quite obviously there is no main class by the name of C:\OraThin) .
Also in your case the complication rises cause you are specifying the value for your "classpath", here along with your other JARs you would also need to include the directory which contains the class file of your OraThin class ( which is what adatapost has done by including "c:" in the classpath as shown here
d:\oracle\product\10.2.0\db1\jdbc\lib;c:\ ).You should try what adatapost has suggested, I ended up giving him a bad cookie cause I failed to observe you are running your programs from inside the bin directory of your JDK installation. Hopefully someone will equalize for my blunder there.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Welcome stephen84s.
>but I get the error:-
Exception in thread "main" java.lang.NoClassDefFoundError: c:\OraThin
Iwould be glad if someone help me.
Have you seen this?
java launcher cannot load the class when it is qualified with path or drive letter.
>but I get the error:-
Exception in thread "main" java.lang.NoClassDefFoundError: c:\OraThin
Iwould be glad if someone help me.
Have you seen this?
java launcher cannot load the class when it is qualified with path or drive letter.
Java Syntax (Toggle Plain Text)
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib c:\OraThin
Last edited by adatapost; Jun 16th, 2009 at 6:38 am.
Failure is not fatal, but failure to change might be. - John Wooden
For your kind consideration try this code:
Create p1.java at c:\ and compile it
Now, change your current directory: Assume that c:\javaprg> is your current directory
What are the options you have to run this program?
Isn't it?
Create p1.java at c:\ and compile it
Java Syntax (Toggle Plain Text)
public class p1{ public static void main(String []args) { System.out.println("hello"); } }
Now, change your current directory: Assume that c:\javaprg> is your current directory
What are the options you have to run this program?
Java Syntax (Toggle Plain Text)
C:\javaprg>java -cp c:\; p1
Isn't it?
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Welcome stephen84s.
>but I get the error:-
Exception in thread "main" java.lang.NoClassDefFoundError: c:\OraThin
Iwould be glad if someone help me.
Have you seen this?
java launcher cannot load the class when it is qualified with path or drive letter.
Java Syntax (Toggle Plain Text)
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib c:\OraThin
CLASSPATH is required to be setup (or to be mentioned on the command line), as you have shown with an example, so that the class-loader knows which all root directories (and/or JARs), it will look for finding (and subsequently loading) all the qualified/non-qualified Java classes referenced by the program.
The reason for 'java.lang.NoClassDefFoundError' is that the launcher can't find a Java class with the name 'c:\OraThin' as it would not treat 'c:\' as the path qualifier of the .class file named 'OraThin.class' instead it would look for a .class file with the name represented by the entire string (including drive letter, colon, and back-slash).
Please let me know if I misunderstood your point.
•
•
Join Date: Jun 2009
Posts: 9
Reputation:
Solved Threads: 0
Thank you all for your helpfull replies.
ok I went to Start -> Control Panel -> System -> Advanced -> Environment Variables
variable name is java_home of course.
but what the variable value?
is it
%SystemRoot%\system32;%SystemRoot%;c:\jdk1.4.2\bin\;
or
c:\jdk1.4.2\bin\;
•
•
•
•
Your have to set environment variable PATH with "C:\j2sdk1.4.1\bin>".
variable name is java_home of course.
but what the variable value?
is it
%SystemRoot%\system32;%SystemRoot%;c:\jdk1.4.2\bin\;
or
c:\jdk1.4.2\bin\;
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
Thank you all for your helpfull replies.
ok I went to Start -> Control Panel -> System -> Advanced -> Environment Variables
variable name is java_home of course.
but what the variable value?
is it
%SystemRoot%\system32;%SystemRoot%;c:\jdk1.4.2\bin\;
or
c:\jdk1.4.2\bin\;
You would just change the JAVA_HOME and everything else would remain unchanged (considering that the directory structure is the same in all the installations). In case you have only one JDK installation, you would probably not mind giving the full path wherever required.
Steps to update your PATH variable with the full path of your JDK bin:-
1. Go to the 'Environment Variables' section (the same way as you have mentioned)
2. Select 'PATH'
3. Edit
4. append 'c:\jdk1.4.2\bin' to the existing value. Separator to be used would be ';' (for Windows). For example: if the existing value of PATH is 'c:\abc;d:\a1;c:\def\ghi' then the updated value should be 'c:\abc;d:\a1;c:\def\ghi;c:\jdk1.4.2\bin'.
Setting the JDK's bin in PATH would ensure that you can invoke the tools like javac (Java Compiler), java (Java Interpreter), and other tools available in the JDK bin directory from any working directory on the system.
You will need to setup PATH even if you have set up JAVA_HOME. It's just that the PATH entry will get little trimmed as you can then setup your PATH by appending ';%JAVA_HOME%\bin' (a variable is required to be enclosed within a pair of '%'s for its value to be picked) to the existing value of the PATH. Hope this helps.
•
•
Join Date: Jun 2009
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
However you may run this program.
Java Syntax (Toggle Plain Text)
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib;c:\; OraThin
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib;c\; jdbc\lib;c;\; OraThin
Exception in thread "main" java.lang.NoClassDefFoundError: jdbc\lib;c;\;
C:\j2sdk1.4.1\bin>set classpath=d:\oracle\product\10.2.0\db1\jdbc\lib;c\; jdbc\lib;c;\; OraThin
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib;c\; jdbc\lib;c;\; OraThin
Exception in thread "main" java.lang.NoClassDefFoundError: jdbc\lib;c;\;
C:\j2sdk1.4.1\bin>java -classpath d:\oracle\product\10.2.0\db1\jdbc\lib;c\; OraThin
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.driver.
OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at OraThin.main(OraThin.java:8)
Do you have suggestion
thank you.
![]() |
Similar Threads
- How to connect Java With Jasper Report (jrxml) (Java)
- how to connect vb6.0 to oracle 9i (Visual Basic 4 / 5 / 6)
- Connect to remote Oracle DB using WAMP (Oracle)
- connect php to oracle 6 (PHP)
- Java Oracle Connectivity (Java)
- Java / Oracle (Wales) (Software Development Job Offers)
- Java and Oracle (Java)
- Java and Oracle (Oracle)
Other Threads in the Java Forum
- Previous Thread: Hmm, UI manager and static JProgressBar?
- Next Thread: Rhombus using Triangle
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image inetaddress integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






