Comment faire pour résoudre “Impossible de créer le pilote JDBC de la classe de com.mysql.jdbc.Un pilote pour connecter URL”
Tout d'abord je tiens à dire que j'ai vérifié toutes les réponses à stackoverflow, et je ne peux pas corriger ce bug! Aider moi s'il vous plaît! Je passe beaucoup de temps, mais aucun résultat.
Je suis en train de créer un pool de connexion à l'aide de Tomcat8.
J'ai une exception:
java.sql.SQLException: Impossible de créer le pilote JDBC de classe
'com.mysql.jdbc.Un pilote pour connecter URL
'jdbc:mysql:/localhost:3306/autopark' à
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2160)
au
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2032)
au
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1532)
à l'ua.khpi.shapoval.db.DbConnector.init(DbConnector.java:31) à
ua.khpi.shapoval.db.DbContextListner.contextInitialized(DbContextListner.java:48)
au
org.apache.catalina.de base.StandardContext.listenerStart(StandardContext.java:4842)
au
org.apache.catalina.de base.StandardContext.startInternal(StandardContext.java:5303)
au
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
au
org.apache.catalina.de base.ContainerBase$StartChild.appel(ContainerBase.java:1407)
au
org.apache.catalina.de base.ContainerBase$StartChild.appel(ContainerBase.java:1397)
à java.util.de façon concomitante.FutureTask.exécuter(FutureTask.java:266) à
java.util.de façon concomitante.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
au
java.util.de façon concomitante.ThreadPoolExecutor$Travailleur.exécuter(ThreadPoolExecutor.java:617)
à java.lang.Fil de discussion.exécution(Thread.java:745) Causés par:
java.sql.SQLException: Aucun pilote approprié à
org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2151)
... Plus de 13
DbConnector.class
public class DbConnector {
private static Logger log = Logger.getLogger(DbConnector.class.getName());
private static DataSource dataSource;
private static Connection connection;
public static void init() throws ServletException, SQLException, NamingException, ClassNotFoundException {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env/");
DataSource ds = (DataSource) envCtx.lookup("jdbc/autopark");
System.out.println(ds.getConnection());
}
public static Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
context.xml que situé dans le répertoire META-INF
<?xml version="1.0" encoding="UTF-8"?>
<Context crossContext="true" reloadable="true">
<Resource name="jdbc/autopark" auth="Container" type="javax.sql.DataSource"
username="root" password="161acid161" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql:/localhost:3306/autopark" maxActive="15" maxIdle="3" />
<ResourceLink name="jdbc/autopark" global="jdbc/autopark"
type="javax.sql.DataSource" />
</Context>
web.xml fichier
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Autostation</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
<description>Db</description>
<res-ref-name>jdbc/autopark</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<listener>
<listener-class>ua.khpi.shapoval.db.DbContextListner</listener-class>
</listener>
</web-app>
Le contenu de mon tomcat/lib répertoire et mon projet de la structure.
je suis limité par l'utilisation de Maven. J'ai besoin d'utiliser de projet web Dynamique
OriginalL'auteur Serg Shapoval | 2016-08-04
Vous devez vous connecter pour publier un commentaire.
L'URL JDBC n'est pas correct, en effet vous avez manque un slash donc, essayez ceci:
Si vous vérifiez bien la véritable erreur est
No suitable driver
ce qui signifie qu'il ne peut pas trouver un pilote JDBC qui prend en charge l'URL fournie.OriginalL'auteur Nicolas Filotto