Salve sto scrivendo una web app che fa uso del pool di connessione di tomcat.
nel file server.xml di tomcat ho inserito
nel file META-INF/context.xml della mia web appcodice:<Context path="/miodb" docBase="miodb" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/miodb" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="miapsw" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/miodb?autoReconnect=true" validationQuery="select count(*) from tabella"/> </Context>
in web.xml della mia applicazionecodice:<Context> <Resource name="jdbc/miodb" auth="Container" type="javax.sql.DataSource” maxActive="100" maxIdle="30" maxWait="10000" username="root" password="miapsw" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/miodb?autoReconnect=true" /> </Context>
nella cartella lib della mia applicazione ho copiato il file mysql-connector-java-5.1.12-bin.jarcodice:<web-app> <description>progetto</description> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/miodb</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </web-app>
la pagina jsp che richiama il servizio è:
Putroppo lanciando il file mi viene ritornato:codice:<%@page isErrorPage = "true" %> <%@page import="java.sql.*"%> <%@page import="javax.naming.*"%> <%@page import="javax.sql.*"%> <html> <head> <title>DB Test</title> </head> <body> <% Connection conn=null; try{ Context ctx = new InitialContext(); if(ctx == null ) throw new Exception("Boom - No Context"); DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/miodb"); if (ds != null) { conn = ds.getConnection(); Statement tmt = (Statement) conn.createStatement(); ResultSet rst = tmt.executeQuery("select * from miodb.tabella"); while (rst.next()) out.println(rst.getString(1)); } }catch(Exception e) { out.println("Errore "+e); } %> </body> </html>
Errore org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
Dove dannsxione sbaglio?
grazie

Rispondi quotando