日期:2014-05-17 浏览次数:20877 次
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Date"%>
<html>
<body>
<%!public static final String DBDRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/test";
public static final String DBUSER = "root";
public static final String DBPASSWORD = "admin";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
%>
<%
try {
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD);
String sql = "select * from emp";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
%>
<center>
<table border="1" width="80%">
<tr>
<td>雇员编号</td>
<td>雇员姓名</td>
<td>雇员工作</td>
<td>雇员工资</td>
<td>雇佣日期</td>
</tr>
<%
while (rs.next()) {
int empno = rs.getInt("empno");
String ename = rs.getString("ename");
String job = rs.getString("job");
Date d = new Date();
d = rs.getDate("hiredate");
float sal = rs.getFloat("sal");
%>
<tr>
<td><%=empno%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=sal%></td>
<td><%=d%></td>
</tr>
<%
}
%>
</table>
</center>
<%
} catch (Exception e) {
System.out.println(e);
} finally {
rs.close();
pstmt.close();
conn.close();
}
%>
</body>
</html>