Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forName("")

 
Mathews P Srampikal
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would imagine that googling for "download oracle jdbc driver" points you in the right direction.
 
Mathews P Srampikal
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error code 12505 means TNS: listener could not resolve SID given in connection description.
[ September 02, 2008: Message edited by: Rene Larsen ]
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Highly unlikely that the problem is with the downloaded .jar.
Please post more details of the Exception.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic