jsp 与 mysql连接

来源:互联网 发布:浦科特m8peg 软件 编辑:程序博客网 时间:2024/05/15 04:54
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@page import="java.sql.*"%>
<%@page contentType="text/html; charset=gb2312"%>
<html>
<style type="text/css">
<!--
.style1 {
 font-family: "宋体";
 font-size: 14px;
}
-->
</style>
<head>
<title>person_show</title>
</head>
<body>
<table>
<table width="800" border="1" cellspacing="0" bordercolor="#336666">
  <tr>
    <td align="center" nowrap>ID</td>
    <td align="center" nowrap ><span class="style1">姓名</span></td>
    <td align="center" nowrap><span class="style1">性别</span></td>
    <td align="center" nowrap><span class="style1">年龄</span></td>
    <td align="center" nowrap><span class="style1">电话</span></td>
    <td align="center" nowrap><span class="style1">住址</span></td>
    <td align="center" nowrap><span class="style1">Email</span></td>
 <td align="center" nowrap><span class="style1">操作</span></td>
  </tr>
  <%
  Class.forName("com.mysql.jdbc.Driver");
  Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/user_table","root","mzq8293");
  Statement stmt = conn.createStatement();
  ResultSet rs = stmt.executeQuery("select * from users");
    while(rs.next())
  {
%>
  <tr class="style1">
     <td align="center" class="style1"><%=rs.getString("id")%></td>
     <td align="center"><%=rs.getString("name")%></td>
     <td align="center"><%=rs.getInt("sex") == 0 ? "男":"女"%></td>
     <td align="center"><%=rs.getString("age")%></td>
     <td align="center"><%=rs.getString("phone")%></td>
     <td align="center"><%=rs.getString("address")%></td>
     <td align="center"><%=rs.getString("email")%></td>
  <td align="center">修改 || 删除</td>
  </tr>
<%
  }
%>
<%
 rs.close();
 stmt.close();
 conn.close();   
%>
</table>
<p align="center">添加&nbsp;&nbsp;&nbsp; 返回</p>
</body>
</html> 
原创粉丝点击