java - 从mysql显示表数据到jsp页面

标签 java mysql jsp

我有

<%@ page import="com.mysql.*" %>
<%@ page import="java.sql.*" %>

<html>
<body>
<div id="content">


    <p>Displaying table contents: </p>

    <table border="0" cellpadding="10">
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Company</th>
                <th>Salary</th>
            </tr>
        </thead>
        <tbody>


            <%
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = null;
                conn = DriverManager.getConnection("jdbc:mysql://localhost:8080/Connection", "username", "password");
                Statement stmt = null;
                stmt = conn.createStatement();
                String query = "select * from employeee";
                ResultSet rs = null;
                rs = stmt.executeQuery(query);
                while(rs.next()){
            %>
            <tr>
                <%
                    int id = rs.getInt("id");
                    String name = rs.getString("name");
                    String company = rs.getString("company");
                    int salary = rs.getInt("salary");
                %>
                <td><%=id %></td>
                <td><%=name %></td>
                <td><%=company %></td>
                <td><%=salary %></td>
            </tr>               

            <%      
                }
            %>

        </tbody>
    </table>
</div>
</body>
</html>

我得到了一个 找不到类 com.mysql.jdbc.Driver 的异常

我已将外部 jar 添加到项目中,并使用相同的代码在普通 java 文件中获得结果。

这里有什么问题吗?

最佳答案

将 mysql jar 放在你的 lib 文件夹中......在本地你可能已经完成了作为外部 jar

关于java - 从mysql显示表数据到jsp页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29321483/

相关文章:

java - 某些jsp页面的间歇性Tomcat ClassNotFoundException

java - 在 JavaFX 中的 ListView 中过滤项目

java - websocket 中的多路复用 channel

java - 如何通过两个线程同步关闭套接字?

php - 无法使用 php 从 mysql 显示 XML 数据

mysql - 连接表 : case statement for no matches?

java - 如何在 Spring Boot 中与 Spring MVC 一起提供遗留 jsp 页面?

java - 验证码使jsp页面上的所有html元素消失

java - 使用动态键将 JSON 解析为 HashMap

mysql - 按性别计算年龄范围