aspose file tools*
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
Author

Class.forName("")

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:

try{
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);
}

Here,
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.

Thanks,
Mats.


Thanks,
Mathews
David O'Meara
Rancher

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
Marshal

Joined: Mar 22, 2005
Posts: 41520
    
  53
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
Hi,

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=
(ERROR=(CODE=12505)(EMFI=4))))

what can be the problem for this?

Thanks,
Mats.
Yogesh Dubey
Greenhorn

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

your exception is
IOException:
Connection refused(DESCRIPTION=(TMP=)(VSNNUM=168821762)(ERR=12505)(ERROR_STACK=
(ERROR=(CODE=12505)(EMFI=4))))

this means that the oracle server has refused connection.

Cause:
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: 1125

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

http://www.oracle.com/technology/tech/java/sqlj_jdbc/index.html

Good Luck,
Avi.
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
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
Highly unlikely that the problem is with the downloaded .jar.
Please post more details of the Exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class.forName("")