aspose file tools*
The moose likes JDBC and the fly likes java.sql.SQLException: No suitable driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: No suitable driver" Watch "java.sql.SQLException: No suitable driver" New topic
Author

java.sql.SQLException: No suitable driver

Brijesh kumar Singh
Greenhorn

Joined: Oct 04, 2009
Posts: 5
I am getting this exception while deploying my application on Tomcate version:5.5.26
Application type: Web based(Spring).
java version: 1.6
Database: Oracle 10g Exp.
Driver: ojdbc6 (from oracle site for java 1.6)
I am attaching jdbc.properties file. And It is running perfeclty fine from inside Eclipse(3.5.1). I have a test class to check the problem.
Real Exception :
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL '"jdbc:oracle:thin:@localhost:1521:orcl"'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)

java code: It running fine. Problem is only from Tomcat deployment.
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String userName = "orbgang";
String password = "admin";

Class.forName("oracle.jdbc.driver.OracleDriver");
java.sql.Driver driver = null;
driver = DriverManager.getDriver(url);

System.out.println("Driver name::"+driver.getMajorVersion());

java.sql.Connection connection = DriverManager.getConnection(url, userName, password);

Statement statement = connection.createStatement();

ResultSet resultSet = statement.executeQuery("select * from COUNTRIES");

while(resultSet.next()) {

System.out.println("countries Name !!"+resultSet.getString("COUNTRY_NAME"));
}
Ankur Rati
Greenhorn

Joined: Oct 04, 2009
Posts: 2
Is oracle jdbc driver in your classpath.
Brijesh kumar Singh
Greenhorn

Joined: Oct 04, 2009
Posts: 5
Hi,
Thanks for the reply.
But why I need that driver in classpath ? Because my application is Web project. All the required libs are in WEB-INF/lib folder. And problem is coming when I am deploying that application on Tomcat.

Thanks,
Brijesh Singh
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3832

Brijesh kumar Singh wrote:But why I need that driver in classpath ? Because my application is Web project. All the required libs are in WEB-INF/lib folder. And problem is coming when I am deploying that application on Tomcat.

Have you put the driver jar file in server's "lib" or applications's "lib" directory? If so, do you have any connection factory configuration ?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Brijesh kumar Singh
Greenhorn

Joined: Oct 04, 2009
Posts: 5
Yes. all the libs files are in req. lib folder. I am using Spring framework. I have configured the connection factory in properties files as:
jdbc.properties:

jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url="jdbc:oracle:thin:@localhost:1521"
jdbc.username=orbgang
jdbc.password=admin
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect

and the content of applicationcontext.xml is :

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>com/orbgangsn/domain/OrganizationType.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
Please use the CODE button, and click "disable smilies in this post". Both will make your posts easier to read.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.sql.SQLException: No suitable driver