0

I'm getting an exception when i start application on tomcat on eclipse.

Version

ojdbc7-12.1.0.1.jar    
apache-tomcat-8.5.31
jdk-8u172-windows-x64

Spring config

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
     <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
     <property name="url" value="${database.connection.url}" />
     <property name="username" value="${database.user}" />
     <property name="password" value="${database.pwd}" />
     <property name="initialSize" value="${database.pool.initialSize}" />
     <property name="maxTotal" value="${database.pool.maxTotal}" />
     <property name="maxIdle" value="${database.pool.maxIdle}" />
     <property name="minIdle" value="${database.pool.minIdle}" />
     <property name="maxWaitMillis" value="${database.pool.maxWaitMillis}" />
</bean>

properties

database.user=dev
database.pwd=dev
database.connection.url=jdbc:oracle:thin@X.X.X.X:1521:DATABASE

The exception :

Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
Caused by: java.sql.SQLException: Cannot create JDBC driver of class 'oracle.jdbc.OracleDriver' for connect URL 'jdbc:oracle:thin@X.X.X.X:1521:DATABASE'
    at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2161)
Caused by: java.sql.SQLException: No suitable driver
    at org.apache.commons.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2152)

I tried to put the driver jar on lib folder of tomcat but same error

I'm getting the error also on Wildfly 10.1.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ucf
  • 21
  • 1
  • 2
  • 7
  • Give a try using: '"jdbc:oracle:thin@//X.X.X.X:1521/DATABASE" – Vivek Jun 13 '18 at 05:10
  • same problem with both oracle.jdbc.driver.OracleDriver and oracle.jdbc.OracleDriver – ucf Jun 13 '18 at 09:05
  • You have a typo in your url, you are missing a colon (`:`) after `thin`. It should be `jdbc:oracle:thin:@X.X.X.X:1521:DATABASE`. See also https://stackoverflow.com/questions/1054105/url-string-format-for-connecting-to-oracle-database-with-jdbc – Mark Rotteveel Jun 13 '18 at 15:01
  • Possible duplicate of [Cause of No suitable driver found for](https://stackoverflow.com/questions/160611/cause-of-no-suitable-driver-found-for) – rkosegi Jun 13 '18 at 15:03
  • @MarkRotteveel Thanks, it worked fine after adding a colon (:) – ucf Jun 14 '18 at 10:37

1 Answers1

-1

I see you are referring to wrong Package inside Oracle 7 jar. Use OracleDriver class name as follows oracle.jdbc.driver.OracleDriver

<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />

You can always open the jar and locate the class for OracleDriver: enter image description here

Please refer to this image to see the OracleDriver class path

yoozer8
  • 7,361
  • 7
  • 58
  • 93
Guna
  • 11
  • 3
  • I'm getting the same error with *oracle.jdbc.driver.OracleDriver* class – ucf Jun 12 '18 at 21:43
  • Other than ojdbc class i dont see any issue with your code. Can you confirm "database.connection.url=jdbc:oracle:thin@X.X.X.X:1521:DATABASE " DATABASE is a Servicename or SID? Please paste the exception again with updated Ojdbc class – Guna Jun 12 '18 at 22:02
  • DATABASE is SID – ucf Jun 12 '18 at 22:17
  • Can you paste the exception again – Guna Jun 12 '18 at 22:19
  • Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL 'jdbc:oracle:thin@X.X.X.X:1521:DATABASE' java.sql.SQLException: No suitable driver – ucf Jun 12 '18 at 22:27
  • May i know your oracle version – Guna Jun 12 '18 at 22:32
  • mu oracle versuin is 12c dialect config is org.hibernate.dialect.Oracle12cDialect – ucf Jun 13 '18 at 00:26
  • This is incorrect advice, the driver to load is `oracle.jdbc.OracleDriver`, see also https://stackoverflow.com/questions/6202653/difference-between-oracle-jdbc-driver-classes – Mark Rotteveel Jun 13 '18 at 15:03