1、项目构思使用JDBC技术连接MySQL数据库,实现对图书管理系统中图书信息旳浏览,增长,修改,删除功能。项目设计1,安装并配置数据库,创立数据库,创立表及添加数据2程序设计1 文献名:index.jsp 图书管理系统 添加图书信息 书名作者价格管理 % Class.forName(com.mysql.jdbc.Driver); Connection con = DriverManager.getConnection(jdbc:mysql:/localhost:3307/school,root,ylx); Statement stmt = con.createStatement(); Strin
2、g s = Select * FROM book; ResultSet rs = stmt.executeQuery(s); while(rs.next() int id=rs.getInt(1); out.println(+rs.getString(2)+rs.getString(3)+rs.getString(4)+修改 删除); rs.close(); stmt.close(); con.close(); % 2文献名:add.jsp 添加图书信息添加图书信息 书名: 价格: 元 %request.setCharacterEncoding(UTF-8);String submi
3、t=request.getParameter(submit);if(submit!=null&!submit.equals() String bookname=request.getParameter(bookname); String author=request.getParameter(author); String price=request.getParameter(price); Class.forName(com.mysql.jdbc.Driver); Connection con = DriverManager.getConnection(jdbc:mysql:/localho
4、st:3307/school,root,ylx); Statement stmt = con.createStatement(); String sql=insert into book(bookname,author,price) values(+bookname+,+author+,+price+); int i=stmt.executeUpdate(sql); if(i=1) out.println(alert(添加成功,单击确定跳转到主页!);); response.setHeader(refresh,1;url=index.jsp); else out.println(alert(添
5、加失败,单击确定返回添加页面!),); response.setHeader(refresh,1;url=add.jsp); stmt.close(); con.close();%3文献名edit.jsp 修改图书信息 修改图书信息 书名: input name=bookname type=text value= input name=author type=text value= 价格: input name=price type=text value=元 input type=hidden name=id value= 4文献名:update.jsp 修改完毕 % request.setC
6、haracterEncoding(UTF-8); String bookname=request.getParameter(bookname); String author=request.getParameter(author); String price=request.getParameter(price); String id=request.getParameter(id); Class.forName(com.mysql.jdbc.Driver); Connection con = DriverManager.getConnection(jdbc:mysql:/localhost:
7、3307/school,root,ylx); Statement stmt = con.createStatement(); String sql=update book set bookname=+bookname+,author=+author+,price=+price+ where id=+id; int i=stmt.executeUpdate(sql); if(i=1) out.println(alert(修改成功,单击确定后自动跳转到主页!);); response.setHeader(refresh,1;url=index.jsp); stmt.close(); con.clo
8、se(); % 5文献名:del.jsp 删除图书信息 % request.setCharacterEncoding(gb2312); Class.forName(com.mysql.jdbc.Driver); Connection con = DriverManager.getConnection(jdbc:mysql:/localhost:3307/school,root,ylx); Statement stmt = con.createStatement(); String id=request.getParameter(id); int i=stmt.executeUpdate(del
9、ete from book where id=+id); if(i=1) out.println(alert(删除成功,单击确定后自动跳转到主页!);); response.setHeader(refresh,1;url=index.jsp); else out.println(alert(删除失败,单击确定后自动跳转到主页!);); response.setHeader(refresh,1;url=index.jsp); con.close(); stmt.close(); % 6文献名:error.jsp error page 错误信息为 项目运行1显示图书信息页面2添加图书信息3添加图书信息成功页面4添加成功返回主页面5. 修改图书信息页面6. 修改成功页面7 删除成功页面创立旳数据库数据库表