【问题标题】:Error: No suitable driver found for jdbc:mysql://localhost:3306/wt错误:找不到适合 jdbc:mysql://localhost:3306/wt 的驱动程序
【发布时间】:2015-02-04 16:28:48
【问题描述】:

我知道我不应该在 JSP 上使用此代码,但我只想检查与数据库的连接。所以我使用它来检查 JSP 页面。但是当我检查它时,它给我一个这样的错误:

Error: No suitable driver found for jdbc:mysql://localhost:3306/wt

database.jsp的源码:

    <section>
      <h3><code>Users</code> Table</h3>
<%
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    String url = "jdbc:mysql://localhost:3306/wt";
    String user = "root";
    String password = "";

    try {
        con = DriverManager.getConnection(url, user, password);
        st = con.createStatement();
        rs = st.executeQuery("SELECT VERSION()");

        if (rs.next()) {
            out.println(rs.getString(1));
        }
    } catch (SQLException ex) {
        System.out.println("Error: " + ex.getMessage());
    }
%>
    </section>

我还将mysql-connector-java-5.1.34-bin.jar 包含在库列表中。我正在使用以下堆栈:

  • MySQL 5.6.17
  • Eclipse Luna(J2EE 视角)
  • JBoss 6.1 分发服务器

请指导我哪里出错了。提前致谢。

【问题讨论】:

    标签: mysql eclipse jsp jdbc


    【解决方案1】:

    加载类:

    Class.forName(mysqlDriverClass).newInstance();
    

    在调用任何 jdbc 方法之前?

    更新


    使用&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%&gt; 包含SQL JSTL 类,并将您的数据源&lt;sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/TEST" user="root" password="pass123"/&gt; 设置为您需要的任何内容。请务必包含jstl jar

    【讨论】:

    • 我收到此错误:org.apache.jasper.JasperException: An exception occurred processing JSP page /Database.jsp at line 33。怎么办?
    • ps:我在.jsp文件中使用它。
    猜你喜欢
    • 1970-01-01
    • 2016-10-01
    • 2012-05-08
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 2013-05-09
    • 2012-07-30
    相关资源
    最近更新 更多