如下代码:
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<%
String id=request.getParameter("stu_id").toString();
String db_driver="com.mysql.jdbc.Driver";
String db_url="jdbc:mysql://127.0.0.1:3306/library?user=root&&password=123456";
int i = 0;
try{
//1加载驱动
Class.forName(db_driver);
//2构建连接
Connection conn=DriverManager.getConnection(db_url);
//3构建执行语句
String sql = "select *from student where id=?";
PreparedStatement pstmt;
pstmt =conn.prepareStatement(sql);
pstmt.setString(1, id);
//i = pstmt.executeUpdate();
ResultSet rs=pstmt.executeQuery();
String stu_id=rs.getString(1);
String stu_name=rs.getString(2);
String stu_pass=rs.getString(3);
int stu_borrow=rs.getInt(4);
pstmt.close();
conn.close();
}
catch (SQLException e) {
e.printStackTrace();
}
response.sendRedirect("Manager.jsp");
%>
</body>
</html>
如何在网页上显示从数据库中获取的 stu_id, stu_name, stu_pass,stu_borrow