i 绝望

依然

Miss Lang

java web 程序---jsp连接mysql数据库的实例基础+表格显示

<%@ 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>

  

posted on 2014-05-26 07:34  juewang  阅读(1204)  评论(0编辑  收藏  举报

绝望依然

Miss Lang