我有
<%@ 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/