First book class.
Slightly
Then a homepage, write a form, submit the book information to Addbook.
Slightly
Addbook.jsp connects to JDBC and inserts it into the Book table.
<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%@ Page Import="java.sql.Connection"%> <%@ Page Import="Java.sql.DriverManager"%> <%@ Page Import="java.sql.PreparedStatement"%> <%@ Page Import="Java.sql.ResultSet"%> <%@ Page Import="java.sql.Statement"%> <%@ Page Import="java.sql.*"%> <%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML> <Head> <Basehref= "<%=basePath%>"> <title>Uuuu</title> <Metahttp-equiv= "Pragma"content= "No-cache"> <Metahttp-equiv= "Cache-control"content= "No-cache"> <Metahttp-equiv= "Expires"content= "0"> <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3"> <Metahttp-equiv= "description"content= "This is my page"> </Head> <Body> <%request.setcharacterencoding ("UTF-8"); %> <Jsp:usebeanID= "book"class= "book" ></Jsp:usebean> <Jsp:setproperty Property=""name= "book"/> <%try{Class.forName ("Oracle.jdbc.driver.OracleDriver"); //NewOracle.jdbc.driver.OracleDriver (); Connection Conn=Drivermanager.getconnection ("Jdbc:oracle:thin: @localhost: 1521:xe", "Yu", "123"); StringSQL= "INSERT into book (Id,name,price,book_count,author) VALUES (?,?,?,?,?)"; PreparedStatement PS=conn.preparestatement (SQL); Ps.setint (1, Book.getid ()); Ps.setstring (2, Book.getname ()); Ps.setdouble (3, Book.getprice ()); Ps.setint (4, Book.getbookcount ()); Ps.setstring (5, Book.getauthor ()); intRow=ps.executeupdate (); if(Row> 0) {Out.print ("it worked." +Row+ "Bar Data"); } ps.close (); Conn.close (); }catch (Exception e) {e.printstacktrace (); } %> <BR> <ahref= "index.jsp">Return</a> </Body></HTML>
The idea is so simple.
The query needs to use resultset.
Modify the SQL statement that requires only update.
Delete the SQL statement that simply deletes.
JDBC enables simple additions and deletions