Index.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<%@page errorpage ="error.jsp"%>
<html>
<head>
<title>图书管理系统</title>
</head>
<body>
<center><a href=add.jsp>添加图书信息</a></center><p>
<table align="center" width="50%" border=1>
<tr><th>书名</th><th>作者</th><th>价格</th><th>管理</th></tr>
<%
Class.forName("sql.jdbc.Driver");
Connection con = Connection("jdbc:mysql://localhost:3307/school","root","ylx");
Statement stmt = ateStatement();
String s = "Select * FROM book";
ResultSet rs = uteQuery(s);
())
{
int Int(1);
out.println("<tr><td>"+rs.getString(2)+"</td></tr>"+rs.getString(3)+"</td></tr>
"+rs.getString(4)+"</td></tr><a href='edit.jsp?id="+id+"'>修改</a> <a href='del.jsp?id="+id+"'>删除</a></td></tr>");
}
rs.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>
Add.jsp
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*" errorPage="error.jsp"%>
<html>
<head>
<title>添加图书信息</title>
</head>
<body>
<form action="add.jsp" method="post">
<table align="center"width="50%" border="1">
<caption>添加图书信息</caption>
<tr>
<th width="30%">书名:</th>
<td width="70%"><input name="bookname" type="text"></td>
</tr>
<tr>
<th>作者:</th>
<td><input name="author" type="text"></td>
</tr>
<tr>
<th>价格:</th>
<td><input name="price" type="text">元</td>
</tr>
<tr>
<th colspan="2">
<input type="submit" name="submit" value="添加">
<input type="reset" value="重置">
</th>
</tr>
</table>
</form>
<%
request.setCharacterEncoding("gb2312");
String Parameter("submit");
if(submit!=null&&!submit.equals(""))
{
String Parameter("bookname");
String Parameter("author");
String Parameter("price");
Class.forName("sql.jdbc.Driver");
Connection con = Connection("jdbc:mysql://localhost:3307/school","root","ylx");
Statement stmt = ateStatement();
String sql="insert into book(bookname,author,price) values('"+bookname+"','"+author+"',"+price+")";
java的jdbc连接数据库
int uteUpdate(sql);
if(i==1)
{
out.println("<script language='javaScript'>alert('添加成功,单击确定跳转到主页!');</script>");
response.setHeader("refresh","1;url=index.jsp");
}
else{
out.println("<script language='javaScript'>alert('添加失败,单击确定返回添加页面!'),</script>");
response.setHeader("refresh","1;url=add.jsp");
}
stmt.close();
con.close();
}
%>
</body>
</html>
Edit.jsp
<%@ page import="java.sql.*" pageEncoding=gb2312" errorPage="error.jsp"%>
<html>
<head>
<title>修改图书信息</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
Class.forName("sql.jdbc.Driver");
Connection con = Connection("jdbc:mysql://localhost:3307/school","root","ylx");
Statement stmt = ateStatement();
String Parameter("id");
ResultSet rs = uteQuery("select*from book where id="+id);
rs.next();
%>
<form action="update.jsp" method="post">
<table align="center"width="50%" border="1">
<caption>修改图书信息</caption>
<tr>
<th width="30%">书名:</th>
<td width="70%"><input name="bookname" type="text" value="<%=rs.getString(2)%>"></td>
</tr>
<tr>
<th>作者:</th>
<td><input name="author" type="text" value="<%=rs.getString(3)%>"></td>
</tr>
<tr>
<th>价格:</th>
<td><input name="price" type="text" value="<%=rs.getString(4)%>">元</td>
</tr>
<tr>
<th colspan="2">
<input type="hidden" name="id" value="<%=id%>">
<input type="submit" value="修改">
<input type="reset" value="重置">
</th>
</tr>
</table>
</form>
<%
rs.close();
stmt.close();
con.close();
%>
</body>
</html>
Update.jsp
<%@ page import="java.sql.*" pageEncoding=gb2312" errorPage="error.jsp"%>
<html>
<head>
<title>修改完成</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String Parameter("bookname");
String Parameter("author");
String Parameter("price");
String Parameter("id");
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论