| Author |
configuring driver class name in init-parameter
|
Swetha Bhagavathula
Ranch Hand
Joined: Jan 04, 2011
Posts: 112
|
|
java.sql.SQLException: No suitable driver found for jdbc : oracle:thin: @localhost: 1521: orcl
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at mydbsrvtest.DBSrvtest.init(DBSrvtest.java:41)
.
.
.
.
.I am facing the above exception when I run my servlet program (in Netbeans 7.0).
I didn't configure driver class name as init parameter value as I am using ojdbc 6.jar.. Is it necssary to add driver class name..?
the following is my web.xml
my html file code is:
and servlet program code is...:
please can anyone tell me where my mistake is..?
|
SCJP5
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
You need to specify it somewhere. Why do you think ojdbc6.jar would be an exception?
see: JDBCConnectionFAQ
|
 |
Swetha Bhagavathula
Ranch Hand
Joined: Jan 04, 2011
Posts: 112
|
|
Tim McGuire wrote:You need to specify it somewhere. Why do you think ojdbc6.jar would be an exception?
see: JDBCConnectionFAQ
i didn't mean ojdbc6.jar is an exception.what i mean is the driver class file is built in for oracle11g that contains ojdc6.jar with driver class file.so we need not specify it explicitely that is we need not load the class by using Class.forName("oracle.jdbc.driver.OracleDriver"); when i use type 4 jdbc driver.
so what i feel is what is the need of mentioning it in init parameters when i add jar file(that is ojdbc 6.jar) in libraries folder of my project (in IDE).If that is the case why am I facing the above error when i run my web application using glassfish 3.x server with net beans 7.0 ide.. please explain me and correct me
|
 |
Tim McGuire
Ranch Hand
Joined: Apr 30, 2003
Posts: 819
|
|
Swetha Bhagavathula wrote:what i mean is the driver class file is built in for oracle11g that contains ojdc6.jar with driver class file. so we need not specify it explicitely that is we need not load the class by using Class.forName("oracle.jdbc.driver.OracleDriver"); when i use type 4 jdbc driver.
The jar file may be there, but somewhere you need to tell your code to use that driver. This is proved by the exception you are getting.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
I don't like this code. You should declare your database connection as a resource, then retrieve it through JNDI. That way the container is in control of the connections, and may even use connection pooling.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Swetha Bhagavathula
Ranch Hand
Joined: Jan 04, 2011
Posts: 112
|
|
Rob Spoor wrote:I don't like this code. You should declare your database connection as a resource, then retrieve it through JNDI. That way the container is in control of the connections, and may even use connection pooling.
can you please describe in detail. I am not aware of how to retrieve through JNDI.. please so that I can learn...
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
For Tomcat:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html#JDBC_Data_Sources
|
 |
Swetha Bhagavathula
Ranch Hand
Joined: Jan 04, 2011
Posts: 112
|
|
|
thank you
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You're welcome.
|
 |
 |
|
|
subject: configuring driver class name in init-parameter
|
|
|