遇到问题:com.mysql.jdbc.Driver class not found 我在项目中的WEB-INF/lib中添加mysql-connector-java-5.6-bin jar包后在eclipse中选中项目刷新,在lib中选中mysql-connector-java-5.6-bin jar右键点击addbulidPath成功解决问题 完整的代码如下:

<%@page import="java.sql.DriverManager" import="java.sql.Connection" import="java.sql.Statement" 
import="java.sql.ResultSet" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","123456");
Statement stmt=conn.createStatement();
String sql="select * from person ";
ResultSet rs=stmt.executeQuery(sql);
%>
<table bgcolor="green" border="1">
<tr>
<td>id</td>
<td>name</td>
<td>sex</td>
<td>age</td>
</tr>
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getString("id") %></td>
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("sex") %></td>
<td><%=rs.getString("age")%></td>
</tr>
<% }%>
</table>
</body>
</html>
posted on 2015-03-25 14:15 张东亮 阅读(123) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: