2015-11-06 55 views
1

我目前使用以下技術堆棧:intellj 14.1.5 ,Spring MVC,tomcat 8.0.28和mysql workbench 6.3。我試圖連接到我的數據庫,但出現錯誤。我覺得問題在於我的context.xml文件。任何幫助表示讚賞。錯誤消息:無法獲取連接,數據源無效:「java.sql.SQLException:無法爲連接URL創建類''的JDBC驅動程序'null'」

什麼我context.xml文件看起來像:

<!-- maxTotal: Maximum number of database connections in pool. Make sure you 
     configure your mysqld max_connections large enough to handle 
     all of your db connections. Set to -1 for no limit. 
     --> 

    <!-- maxIdle: Maximum number of idle database connections to retain in pool. 
     Set to -1 for no limit. See also the DBCP documentation on this 
     and the minEvictableIdleTimeMillis configuration parameter. 
     --> 

    <!-- maxWaitMillis: Maximum time to wait for a database connection to become available 
     in ms, in this example 10 seconds. An Exception is thrown if 
     this timeout is exceeded. Set to -1 to wait indefinitely. 
     --> 

    <!-- username and password: MySQL username and password for database connections --> 

    <!-- driverClassName: Class name for the old mm.mysql JDBC driver is 
     org.gjt.mm.mysql.Driver - we recommend using Connector/J though. 
     Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver. 
     --> 

    <!-- url: The JDBC connection url for connecting to your MySQL database. 
     --> 

    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" 
      maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
      username="root" password="1234" driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:3306/module1"/> 

我加入到我的web.xml什麼:

<resource-ref> 
    <description>DB Connection</description> 
    <res-ref-name>jdbc/TestDB</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

什麼我的JSP文件看起來像:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> 
    <html> 
     <body> 
     <h1>Test1</h1> 

     <sql:query var="rs" dataSource="jdbc/TestDB"> 
      select id from myguests 
     </sql:query> 

     <c:forEach var="row" items="${rs.rows}"> 
      ID: ${row.id}<br/> 
     </c:forEach> 

     </body> 
    </html> 

我也有我的pom.xml文件下列依賴性:

<dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.37</version> 
    </dependency> 
+1

請勿在此發佈指向文字圖片的鏈接,甚至不要發佈圖片。發佈文字。完全浪費你的時間和帶寬。 – EJP

+0

我很抱歉。我是新來堆棧溢出,並沒有意識到這將是一個問題。 –

回答

1

我能解決我的問題。看來我需要在webapp目錄中創建一個META-INF目錄。一旦我這樣做了,我把context.xml文件放在META-INF目錄中,並糾正了這個問題。