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>
相關文章
相關標籤/搜索