JSP写的图书管理系统部分代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
PreparedStatement ps = con.prepareStatement("select * from t_book");
ResultSet rs = ps.executeQuery();
//每页显示3条,得到总页数rs.last();//游标指针滚动到最后一行int row = rs.getRow();//得到当前记录行数int pages = row%3!=0?row/3+1:row/3;//计算出总页数rs.beforeFirst();//还原到首行之前//定位器
{
ResultSet rs = null;
try {
conn
DriverManager.getConnection(connStr,user,password);
stmt = conn.createStatement(); =
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
<table width="600" border="1" align="center" bgColor="#ffffff"> <caption>
<span class="STYLE1"><br><br><br>图书管理面板</span> </caption>
<tr>
<td width="98" bgColor="#808000">全选
value="<%=rs.getInt("id") %>"></td>
<td><%=rs.getInt("id") %></td>
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("publish") %></td>
<td><%=rs.getInt("price") %></td> name="ids"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>图书管理面板</title>
private String password = "091658";
private Connection conn = null;
private Statement stmt = null;
public DBbean()
{
try {
Class.forName(driverStr);
} catch (ClassNotFoundException e) {
<style type="text/css">
<!--
.STYLE1 {
font-size: 36px;
font-weight: bold;
}
-->
</style>
</head>
<body background="image\3.jpg">
<form name="form1" method="get" action="bookDel.jsp">
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setDriverStr(String dstr)
{
driverStr=dstr;
}
public void setConnStr(String cstr)
{
connStr=cstr;
}
catch(SQLException ex){
System.out.println(ex.getMessage()); }
}
}
=
3.3.3首页设计
login.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
</table>
</form>
</body>
</html>
3.3.4页面设计
bookList.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
if(strPage!=null){
curPage=Integer.parseInt(strPage);
}
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bk","root","123");
<td width="166"
bgColor="#808000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户名:</td>
<td width="318" bgColor="#808000"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td
bgColor="#808000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密码:</td>
<td bgColor="#808000"><input name="password" type="password" id="password"></td>
}
public void setUser(String user)
{
this.user = user;
}
public void setPassword(String password)
{
this.password = password;
}
public ResultSet executeQuery(String sql)
</td>
</tr>
</table>
</form>
</body>
</html>
1、添加图书信息界面:
bookAdd.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
result = stmt.executeUpdate(sql); }
catch(SQLException ex){
System.out.println(ex.getMessage()); }
return result;
}
public void close()
{
try{
stmt.close();
conn.close();
3.3.2数据库连接模块设计数据库连接DBbean文件:DBbean.class:
package dbbean;
import java.sql.*;
public class DBbean
{
private String driverStr = "com.mysql.jdbc.Driver";
private String connStr = "jdbc:mysql://localhost:3306/bk"; private String user = "root";
<input type="checkbox" name="checkbox" value="checkbox"></td> <td width="98" bgColor="#808000">编号</td>
<td width="118" bgColor="#808000">书名</td>
<td width="108" bgColor="#808000">出版社</td>
<table width="420" height="182" border="0" align="center" bgColor="#c0c0c0">
<caption>
<span class="STYLE1"><br><br><br>登陆图书管理系统<br></span> </caption>
<tr>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>添加图书信息</title>
</tr>
<tr>
<td colspan="2" align="center" bgColor="#408080"><input type="submit" name="Submit" value="登录">
<input type="reset" name="Submit2" value="取消"></td> </tr>
<td width="78" bgColor="#808000">价格</td>
<td width="60" bgColor="#808000">操作</td>
</tr>
<%
String strPage=request.getParameter("page");
int curPage=1;//当前显示的页数
<style type="text/css">
<!--
.STYLE1 {
font-size: 36px;
font-weight: bold;
}
-->
</style>
</head>
<body bgcolor="" background="image\3.jpg">
<form name="form1" method="post" action="valid.jsp">
<td><a href="bookEdit.jsp?id=<%=rs.getInt("id")%>">编辑</a></td>
</tr>
<%
}
con.close();
%>
<tr>
<td colspan="6" align="center" bgColor="#ff8000"><input type="submit" name="Submit" value="删除图书">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录图书管理系统</title>
<input name="add" type="button" id="add" value="添加图书" onClick="location='bookAdd.jsp'">
<a href="bookList.jsp?page=1">首页</a>
<a href="bookList.jsp?page=<%=curPage-1 %>">上一页</a> <a href="bookList.jsp?page=<%=curPage+1 %>">下一页</a> <a href="bookList.jsp?page=<%=pages %>">尾页</a>
System.out.println(ex.getMessage()); }
return rs;
}
public int executeUpdate(String sql)
{
int result=0;
try{
conn
DriverManager.getConnection(connStr,user,password); stmt = conn.createStatement();
int position = (curPage-1)*3; if(position!=0){ rs.absolute(position); }
int count=0;//计数器
while(rsห้องสมุดไป่ตู้next()&&count<3){
count++;
%>
<tr>
<td><input type="checkbox"
相关文档
最新文档