File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
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
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
I would imagine that googling for "download oracle jdbc driver" points you in the right direction.
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: 1141

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: 46368
Highly unlikely that the problem is with the downloaded .jar.
Please post more details of the Exception.
I agree. Here's the link:
subject: Class.forName("")
jQuery in Action, 3rd edition