java.sql.SQLException: No suitable driver found jd

2019-09-10 09:35发布

问题:

I am trying to deploy a spring based web application in my local tomcat server. Below are my application details:

  • Spring based web application (war)
  • Tomcat 6 server
  • Java 1.6
  • Oracle DB
  • Below are by jdbc configuration:

    Configuration for tomcat settings only. javax.persistence.jdbc.drive=oracle.jdbc.OracleDriver javax.persistence.jdbc.url=jdbc:oracle:thin:@coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS javax.persistence.jdbc.user=test javax.persistence.jdbc.password=test

  • I have also added ojdbc6.jar,ojdbc14.jar in my /lib folder

I deployed my war file without any issues. But when my application tries to connect to db it throws the error:"java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@coursesdev.cvbaybp20ew7.eu-west"

Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243):  org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for  jdbc:oracle:thin:@coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
Error Code: 0
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:294)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
    at org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:445)
   at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)
    ... 81 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.connectInternal(DatabaseAccessor.java:293)
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:418)
    at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:216)
    at org.eclipse.persistence.sessions.server.ConnectionPool.startUp(ConnectionPool.java:504)
    at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:484)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:208)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
    ... 87 more
Caused by: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@coursesdev.cvbaybp20ew7.eu-west-1.rds.amazonaws.com:1521:DEVCRS
    at java.sql.DriverManager.getConnection(DriverManager.java:602)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
    ... 97 more

I have seen a lot of post with the similar issue but am not sure what i am missing though.

回答1:

This error is depends on your building structure. Adding jar file to your lib folder is not gonna do anything. You should add the jar file to your classpath. If you are building your project by IDE, lets say eclipse, you should add it to .classpath file. If you are using Idea you should add it to your .iml file and etc. If you are building your project by ant you should add jar address to your build.xml file. I suppose you are not using maven.