Zum einen lösen möchte ich sagen, dass ich alle Antworten auf Stackoverflow überprüft, und ich diesen Fehler nicht beheben können! Hilf mir bitte! Ich verbringe viel Zeit, aber kein Ergebnis. Ich versuche Connection-Pool mit Tomcat8 zu erstellen. Ich habe eine Ausnahme:Wie „JDBC-Treiber der Klasse erstellen‚com.mysql.jdbc.Driver‘für connect URL kann nicht“
java.sql.SQLException: Kann nicht JDBC-Treiber der Klasse erstellen 'com.mysql.jdbc.Driver' für connect URL 'jdbc: mysql:/localhost: 3306/Autopark' bei org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory (BasicDataSource.java:2160) bei org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource (BasicDataSource.java:2032) bei org. apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection (BasicDataSource.java:1532) bei ua.khpi.shapoval.db.DbConnector.init (DbConnector.java:31) bei ua.khpi.shapoval.db.DbContextListner.contextInitialized (DbContextListner.java:48) bei org.apache.catalina.core.StandardContext.listenerStart (StandardContext.java:4842) bei org.apache.catalina.core .StandardContext.startInternal (StandardContext.java:5303) bei org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:147) bei org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase .java: 1407) bei org.apache.catalina.core.ContainerBase $ StartChild.call (ContainerBase.java:1397) bei java.util.concurrent.FutureTask.run (FutureTask.java:266) bei java. util.concurrent.ThreadPoolExecutor.runWorker (Th readPoolExecutor.java:1142) bei java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:617) bei java.lang.Thread.run (Thread.java:745) Verursacht durch: java.sql .SQLException: keine geeigneten Treiber bei org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory (BasicDataSource.java:2151) ... 13 weitere
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 die
<?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 Datei
<?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>
Inhalt meiner tomcat/lib Verzeichnis und meine Projektstruktur in META-INF-Ordner.
Ich denke, das ist der falsche Name für den mysql Connector-Treiber. Ich empfehle Ihnen, Maven zu verwenden, um Ihre Projektabhängigkeiten zu verwalten – Julian
@Julian, ich bin durch die Verwendung von Maven eingeschränkt. Ich muss dynamisches Webprojekt verwenden –