首页 > 应用开发 > Java > JSP(4) - 增加客户模块
分成before和after两个界面。before界面用于让用户输入顾客信息,after界面用于后台处理。
要点
1)jsp中引入java类
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
2)得到系统当前时间,并自定义格式显示在网页中
<% Date d = new Date();
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE); %>
......
最后修改日起:
before页:
add_cust_aft.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
String sCustID2 = new String(sCustID.getBytes("iso-8859-1"),"GBK");
String sCustName2 = new String(sCustName.getBytes("iso-8859-1"),"GBK");
String sCustAddr2 = new String(sCustAddr.getBytes("iso-8859-1"),"GBK");
String sCustPhOff2 = new String(sCustPhOff.getBytes("iso-8859-1"),"GBK");
String sCustPhHom2 = new String(sCustPhHom.getBytes("iso-8859-1"),"GBK");
if (sCustID.equals("")){
throw new Exception("客户卡号不准为空.");
}
if (sCustName.equals("")){
throw new Exception("客户姓名不准为空");
}
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@TCSCH074.tcsgdccn.com:1521:orcl";
//orcl为你的数据库的SID
String user="store";
String password="store";
Connection conn= DriverManager.getConnection(url,user,password);
String sInsert = null;
Statement stmt = null;
try{
sInsert = "insert into customer(cst_id,cst_name,cst_sex, cst_year,cst_month,cst_address,cst_zip_code,";
sInsert = sInsert + "cst_ph_office, cst_ph_home, cst_mobile, cst_email, cst_discount, cst_trd_sum,";
sInsert = sInsert + "cst_crt_date, cst_upt_date) values('"+sCustID2+"','"+sCustName2+"','"+sCustSex+"','"+sCustYear+"','"+sCustMonth
+"','"+sCustAddr2+"','"+sCustZip+"','"+sCustPhOff2+"','"+sCustPhHom2+"','"+sCustMob+"','"+sCustEmail+"',"+
fCustDis+","+fCustTtSum+",to_date('"+dCustAdd+"','yyyy-mm-dd'),to_date('"+dCustUpt+"','yyyy-mm-dd'))";
stmt = conn.createStatement();
stmt.execute(sInsert);
conn.commit();
out.println("增加用户"+sCustName2+"完成");
}
catch(Exception e){
System.out.println("新增用户失败!");
e.printStackTrace();
out.println("
新增用户失败!
");%>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/207/viewspace-799591/ ,如需转载,请注明出处,否则将追究法律责任。