2016-06-14 82 views
0

我試圖使用JNDI查找獲取連接池,但有以下錯誤:java.sql.SQLException中:不能「的連接網址」創建一流的「JDBC驅動程序無效」JNDI查找連接池

我上下文XML放置在幅/ WEB-INF文件夾鄰近的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
 
<Context antiJARLocking="true" crossContext="true" reloadable="true" path="patient/account"> 
 
    <Resource 
 
      name="jdbc/pharmacy" 
 
      author="Container" 
 
      type="javax.sql.DataSource" 
 
      maxActive="32" 
 
      maxIdle="8" 
 
      maxWait="10000" 
 
      username="root" 
 
      password="23810198vas" 
 
      driverClassName="com.mysql.jdbc.Driver" 
 
      url="jdbc:mysql://localhost:3306/pharmacy" /> 
 
</Context>

Context envCtx = new InitialContext(); 
    DataSource ds = (DataSource)envCtx.lookup("java:comp/env/jdbc/pharmacy"); 
    Connection connection = ds.getConnection(); 
+1

對於Tomcat,context.xml應該位於** META-INF **之下,並且** META-INF **文件夾應該與** WEB-INF **文件夾位於同一級別。 – Roshith

+0

謝謝!現在正在工作 –

回答

1

對於Tomcat,context.xml中應該是下ME TA-INF和META-INF文件夾應與WEB-INF文件夾處於同一級別。