管理员操作1

接下来要实现管理员对图书进行添加、删除及更新操作的功能。此处对图书信息的操作中,要在页面中输入图书信息,再将其插入到数据库中。

例如:对图书进行插入操作

 

 

addbook.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"

    pageEncoding="gb2312"%>

<!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=ISO-8859-1">

<title>添加书籍</title>

</head>

<body background=C:\Users\Administrator\Desktop\image\2.jpg>

<pre>              管理员添加书籍</pre>

<form action="insertbook.jsp" method="post" >

 书名:<input type="text" name="t1"><br>

 简介:<input type="text" name="t2"><br>

 库存:<input type="text" name="t3"><br>

 分类:<input type="text" name="t4"><br>

  售价:<input type="text" name="t5"><br>

 <input type="submit" name="button" value="提交">

</form>

 </body>

</html>

 

 对数据库进行插入insertbook.jsp

<%@ page language="java" contentType="text/html; charset=gb2312" import="java.sql.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.sql.*,java.io.*,java.lang.*,java.util.*"%>

<% request.setCharacterEncoding("gb2312");%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>插入图书</title>

</head>

<body>

<%

 String t1=request.getParameter("t1");

 String t2=request.getParameter("t2");

 String t3=request.getParameter("t3");

 String t4=request.getParameter("t4");

 int t5=Integer.parseInt(request.getParameter("t5"));

 String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

 String USER = "sa";

 String PASSWORD = "123456";

 String URL = "jdbc:sqlserver://localhost:1433;databaseName=book";

Class.forName(DRIVER);

Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);

 Statement stmt=conn.createStatement();

String sql="INSERT INTO bookinfo(bookID,bookName,intro,inventory,classify,sell) values('002','"+t1+"','"+t2+"','"+t3+"','"+t4+"','"+t5+"')";

stmt.executeUpdate(sql);

out.print("插入成功!");

%>

 </body>

</html>

posted @ 2016-06-21 13:04  构建之法  阅读(197)  评论(0编辑  收藏  举报