wood burning stoves 2.0*
The moose likes JDBC and the fly likes getting class not found exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "getting class not found exception" Watch "getting class not found exception" New topic
Author

getting class not found exception

Vibhas Kumar
Greenhorn

Joined: Oct 13, 2009
Posts: 28
Hi friends i am facing the following error while trying to connect to a database through java code:
Exception in thread "Main Thread" java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.example.model.Driver.main(Driver.java:13)
My java code is:
package com.example.model;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Driver {
public static void main(String args[]) throws ClassNotFoundException,
SQLException {

Class.forName("oracle.jdbc.OracleDriver");
// or you can use:
// DriverManager.registerDriver(
// new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbcracle:thin:@127.0.0.1:1521:ORCL", "scott", "tiger");

Statement stmt = conn.createStatement();
ResultSet rset = stmt
.executeQuery("select * from customer");
while (rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close();


}
}


As per i came to know it could be due to class path issue but don't know how to resolve

my class path is showing following thing
Variable value: oracle.jdbc.OracleDriver

and path is showing :
C:\app\admin\product\11.2.0\dbhome_1\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\

Can anyone suggest me what to do.

Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Vibhas Kumar wrote:
...
my class path is showing following thing
Variable value: oracle.jdbc.OracleDriver
...
Your classpath should contain location and name of the Oracle jdbc library (e.g.: c:\mylibs\oracle\odbc14.jar)


OCUP UML fundamental and ITIL foundation
youtube channel
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vibhas Kumar
Greenhorn

Joined: Oct 13, 2009
Posts: 28
Hi Jan i downloaded a classes12.jar file and put it into C:\bea\user_project\workspace\jdk160_05\jre\lib\ext folder and set the class path as well but still i am getting the same error.

Kindly suggest.
Ramon Gonzalez
Greenhorn

Joined: Jul 26, 2010
Posts: 2
Can you post your class path? And the process you go through to change, you might have it pointed to the wrong directory.


RJ
john chris
Greenhorn

Joined: Aug 02, 2010
Posts: 8
oracle.jdbc.driver.OracleDriver

not "oracle.jdbc.OracleDriver"
Vibhas Kumar
Greenhorn

Joined: Oct 13, 2009
Posts: 28
Hi friends still i am unable to resolve this issue. I set my class path to C:\bea\user_project\workspace\wlserver_10.3\server\ext\jdbc\oracle\11g\ojdbc5.jar;

i am using weblogic 10.3 workspace and weblogic 10.3 server.

what mistake i could possibly would have made kindly suggest.I am also attaching my data source of web-logic admin console .



[Thumbnail for AdminConsole.jpg]

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

You are trying to run a standalone class against the DB, right? So how do you run the class (i.e: command)?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting class not found exception