wood burning stoves 2.0*
The moose likes JDBC and the fly likes Class.forName( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Class.forName("")" Watch "Class.forName("")" New topic


Mathews P Srampikal
Ranch Hand

Joined: Nov 26, 2002
Posts: 211
hi ,
I have to get a connection and do databse operations. I know the following things. but how to make set up to avoid ClassNotFoundException.

code is:

Class c = Class.forName("OracleDriverName");
Connection connection = DriverManager.getConnection("URL","USER","PWD");
System.out.println("helloWorld: = "+c);
}catch(Exception e ){
System.out.println("Exception is = "+e);

Class c = Class.forName("OracleDriverName");

here, where the OracleDriverName is put, and from where we can download the oracle driver.please let me know the URL, where i can download the oracle driver.


David O'Meara

Joined: Mar 06, 2001
Posts: 13459

It should bbe the fully qualified name of the Oracle driver, unless you are using Java 6 and Oracle's JDBC 4.0 driver, in which case that line is no longer required (Oh happy days!)

Either way you'll still need the jdbc driver from oracle.com
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41114
I would imagine that googling for "download oracle jdbc driver" points you in the right direction.

Ping & DNS - my free Android networking tools app
Mathews P Srampikal
Ranch Hand

Joined: Nov 26, 2002
Posts: 211

I downloaded the driver and: now problem in getting connection

Class.forName("oracle.jdbc.driver.OracleDriver");//works fine
Connection conn = DriverManager.getConnection ("jdbcracle:thin:@sonny:1521:ORCLADMIN", "SCOTT", "TIGER");

The error is:

Exception is >>>>> ClassNotFoundException = java.sql.SQLException: Io exception:
Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821762)(ERR=12505)(ERROR_STACK=

what can be the problem for this?

Yogesh Dubey

Joined: Sep 02, 2008
Posts: 2
I think there is nor ClassNotFoundException

your exception is
Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821762)(ERR=12505)(ERROR_STACK=

this means that the oracle server has refused connection.

1. Oracle is not started.
2. Credentials are not correct.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Error code 12505 means TNS: listener could not resolve SID given in connection description.
[ September 02, 2008: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

For me, the best way to learn is to read the documentation.
Have you seen this Web page:


Good Luck,
Mathews P Srampikal
Ranch Hand

Joined: Nov 26, 2002
Posts: 211
hi all thank you very much.

now i am getting onother exception :

java.lang.ArrayIndexOutOfBoundsException: 7

I think, this is the problem with downloaded jar file. will post the result after testing.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38016
Highly unlikely that the problem is with the downloaded .jar.
Please post more details of the Exception.
It is sorta covered in the JavaRanch Style Guide.
subject: Class.forName("")
Similar Threads
How I know what JDBC driver i to use and where i can get this driver name
Problem with conn to oracle
The Network Adapter could not establish the connection in jdbc connection
Not able to connect with SQLServer from java.
Network could not establish connection in jdbc