0

I'm trying to connect Oracle database using this tutorial I have put ojdbc6.jar in the same folder with OracleJDBC.java.

But it gives me an error:

-------- Oracle JDBC Connection Testing ------
Where is your Oracle JDBC Driver?
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at jaa.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at OracleJDBC.main(OracleJDBC.java:13)

Don't understand what is the problem?

10
  • The tutorial tells you to run it as java -cp ..., so did you do that, and use the OS X paths to the .jar and your compiled class, rather than the Windows paths in their example? Commented Sep 18, 2013 at 10:38
  • yes, i'he rune that command and i use my os x path, it runs and do nothing, then i run next command user-vaio:src apple$ java -cp ojdbc6.jar;OracleJDBC Commented Sep 18, 2013 at 11:20
  • You need both elements of the cp, as GyroGearless showed - though I'd slightly prefer the full paths, e.g. java -cp $PWD/ojdbc6.jar:$PWD OracleJDBC. That works for me with the code from that site. Commented Sep 18, 2013 at 11:26
  • Do I need to save tnsname.ora? it shows -------- Oracle JDBC Connection Testing ------ Oracle JDBC Driver Registered! Connection Failed! Check output console java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) Commented Sep 18, 2013 at 12:31
  • You don't need a tnsnames.ora for this, no. Did you change the values in the DriverManager.getConnection() call to something appropriate for the DB you're trying to connect to? Commented Sep 18, 2013 at 13:12

1 Answer 1

2

It might be unexpected for a mac user, but it is not enough to drop a jar in a folder to make things work.

Try something like

java -cp .:odbc6.jar OracleJDBC
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you, but where to try it? in terminal?
Now it says:-------- Oracle JDBC Connection Testing ------ Oracle JDBC Driver Registered! Connection Failed! Check output console java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
Do I need to save tnsname.ora?
I think there is no need to have a tnsnames.ora for a pure Java JDBC driver (but i haven't been working with Oracle for quite a while, so i might be wrong). Maybe post your connection code and the exact connection URL you use!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.