This case is the Query System for entering coffee sales information
I. Data Input System:
1. design input information page
The Code is as follows:
<Html>
<Head>
</Head>
<Body>
<Center> <H1> coffee management system-entry system </H1> </center>
Welcome to the Entry System <br/>
<Form action = "inputaction. jsp" method = "post" name = "form1" id = "form1">
<Center>
Coffee name: <input type = "text" style = "width: 150px" name = "cof_name" id = "cof_name"> <br/>
Supplier ID: <input type = "text" style = "width: 150px" name = "sup_id" id = "sup_id"> <br/>
Product price: <input type = "text" style = "width: 150px" name = "price" id = "price"> <br/>
Sales volume: <input type = "text" style = "width: 150px" name = "sales" id = "sales"> <br/>
Total: <input type = "text" style = "width: 150px" name = "total" id = "total"> <br/>
<Input type = "submit" value = "submit data">
</Center>
</Form>
</Body>
</Html>
2. design and process the oracle database input request webpage inputaciton. jsp
(1) The page is as follows:
(2) Database Design:
SQL> desc coffees;
Name Null? Type
-----------------------------------------------------------------------------
COF_NAME VARCHAR2 (32)
SUP_ID NUMBER (38)
Price float (126)
Sales number (38)
Total number (38)
(3) The input code for processing the database is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "GBK" %>
<% @ Page
Import = "java. SQL. Connection"
Import = "java. SQL. ResultSet"
Import = "java. SQL. SQLException"
Import = "java. SQL. Statement"
%>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Body>
<Center> <H1> coffee management system-entry system </H1> </center>
Inputting <br/>
<%
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Java. SQL. DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
String url = "jdbc: oracle: thin: @ 100.100.100.20: 1521: dbsid2 ";
String user = "scott ";
String password = "tiger ";
Connection con = java. SQL. DriverManager. getConnection (url, user, password );
// Obtain the logon Username
String cof_name = request. getParameter ("cof_name ");
String sup_id = request. getParameter ("sup_id ");
String price = request. getParameter ("price ");
String sales = request. getParameter ("sales ");
String total = request. getParameter ("total ");
String SQL = "insert into coffees values ('" + cof_name + "'," + sup_id + "," + price + "," + sales + ", "+ total + ")";
Statement smt = con. createStatement ();
Int rsw.smt.exe cuteUpdate (SQL );
%>
Input successful <br>
<Form action = "output. jsp" name = "form3" id = "form3">
<Input type = "submit" value = "query result">
</Form>
</Body>
</Html>
Ii. Query System
1. input the request page output. jsp
The Code is as follows:
<Html>
<Head> <Body>
<Center> <H1> coffee management system-Query System </H1> </center>
<Form action = "action. jsp" method = "post" name = "form2" id = "form2">
<Center>
Coffee name: <input type = "text" style = "width: 150px" name = "cof_name_1" id = "cof_name_1"> <br/>
<Input type = "submit" value = "submit query">
</Center>
</Form>
</Body>
</Html>
2. query request processing action. jsp
(1) query result page
(2) The code for processing database queries is as follows:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "GBK" %>
<% @ Page
Import = "java. SQL. Connection"
Import = "java. SQL. ResultSet"
Import = "java. SQL. SQLException"
Import = "java. SQL. Statement"
%>
<%
String path = request. getContextPath ();
String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/";
%>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN">
<Html>
<Head>
<Body>
<Center>
<Table border = "1">
<%
Class. forName ("oracle. jdbc. driver. OracleDriver ");
Java. SQL. DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
String url = "jdbc: oracle: thin: @ 100.100.100.20: 1521: dbsid2 ";
String user = "scott ";
String password = "tiger ";
Connection con = java. SQL. DriverManager. getConnection (url, user, password );
// Obtain the logon Username
String cof_name_1 = request. getParameter ("cof_name_1 ");
// String SQL = "select * from coffees where cof_name =" + "'" + cof_name_1 + "'";
String SQL = "select * from coffees where cof_name =" + "'" + cof_name_1 + "'";
Statement smt = con. createStatement ();
ResultSet rs1_smt.exe cuteQuery (SQL );
While (rs. next ()){
String s1 = rs. getString (1 );
Int s2 = rs. getInt (2 );
Float s3 = rs. getFloat (3 );
Int s4 = rs. getInt (4 );
Int s5 = rs. getInt (5 );
%>
<Tr>
<Td> <% = s1 %> </td>
<Td> <% = s2 %> </td>
<Td> <% = s3 %> </td>
<Td> <% = s4 %> </td>
<Td> <% = s5 %> </td>
</Tr>
<% }%>
</Table>
Query successful <br>
</Center>
</Body>
</Html>