<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <center>JSP连接mysql数据库</center> <% Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=123"); Statement stm=conn.createStatement(); //stm.executeUpdate("insert into shop values (‘男‘,‘林俊杰‘,‘323‘)"); ResultSet rs=stm.executeQuery("select * from shop"); out.print("<table border=‘1‘>"); out.print("<tr><td>性别:</td><td>姓名:</td><td>密码:</td></tr>"); while(rs.next()){ out.print("<tr>"); out.print("<td>"+rs.getString("sex")+"</td>"); out.print("<td>"+rs.getString("name")+"</td>"); out.print("<td>"+rs.getString("pass")+"</td>"); out.print("</tr>"); } out.print("</table>"); %> </body>