本案例为咖啡销售情况录入查询系统
一、数据输入系统:
1. 设计输入信息页面
代码如下:
咖啡管理系统——录入系统
欢迎来到录入系统
vcm0gYWN0aW9uPQ=="inputaction.jsp" method="post" name="form1" id="form1">
咖啡名称:
供应商ID:
商品价格:
销售量:
总量:
2. 设计处理oracle数据库输入请求网页inputaciton.jsp
(1)页面如下:
(2)数据库设计如下:
SQL> desc coffees;
Name Null? Type
----------------------------------------- -------- ----------------------------
COF_NAME VARCHAR2(32)
SUP_ID NUMBER(38)
PRICE FLOAT(126)
SALES NUMBER(38)
TOTAL NUMBER(38)
(3)处理数据库输入代码如下:
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+"/";
%>
咖啡管理系统——录入系统
正在执行录入
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);
//取得登录用户名
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 rs=smt.executeUpdate(sql);
%>
录入成功
二、查询系统
1. 输入请求页面output.jsp
代码如下:
咖啡管理系统—查询系统
2. 查询请求的处理action.jsp
(1)查询结果页面
(2)处理数据库查询代码如下:
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+"/";
%>
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);
//取得登录用户名
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 rs=smt.executeQuery(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);
%>
查询成功