📄 custmerdao.java
字号:
package com.mobile.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.mobile.bean.Operator;
import com.mobile.bean.TCustomer;
public class CustmerDAO {
public int addCustomer(TCustomer tc) {
int ret;
Connection con = null;
ResultSet rs = null;
ret = 0;
PreparedStatement pstmt;
PreparedStatement pstmt1;
try {
con = ConnectionMgr.getConnection();
System.out.println("insert into TCustomer(Customer_ID,id_type,id_number,customer_name,customer_birthday,customer_sex,customer_address) values(?,?,?,TO_DATE('"+ tc.getCustomerBirthday()+"','YYYY-MM-DD'),?,?)");
String sql="insert into TCustomer(Customer_ID,id_type,id_number,customer_name,customer_birtyday,customer_sex,customer_address) values(customer_sequence.nextval,?,?,?,TO_DATE('"+ tc.getCustomerBirthday()+"','YYYY-MM-DD'),?,?)";
pstmt = con
.prepareStatement(sql);
System.out.println(tc.getCustomerAddress()+"/////////////////////");
pstmt.setString(1, tc.getIdType());
pstmt.setString(2, tc.getIdNumber());
pstmt.setString(3, tc.getCustomerName());
pstmt.setString(4, Character.toString(tc.getCustomerGender()));
pstmt.setString(5, tc.getCustomerAddress());
pstmt.executeUpdate();
String sql1="select Customer_ID from TCustomer where id_number="+tc.getIdNumber();
pstmt1=con.prepareStatement(sql1);
rs=pstmt1.executeQuery();
while(rs.next()){
ret=rs.getInt(1);
}
System.out.println(ret);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
public TCustomer CheckCustomer(String type, String number) {
int ret;
Connection con = null;
ResultSet rs = null;
ret = 0;
TCustomer tc = null;
PreparedStatement pstmt;
try {
con = ConnectionMgr.getConnection();
String sql = "select * from TCustomer where ID_Number='"+number+"'";
pstmt = con.prepareStatement(sql);
System.out.println(sql);
rs = pstmt.executeQuery();
System.out.println(tc);
while (rs.next()) {
tc = new TCustomer();
tc.setCustomerId(rs.getInt(1));
tc.setIdType(rs.getString(2));
tc.setIdNumber(rs.getString(3));
tc.setCustomerName(rs.getString(4));
tc.setCustomerBirthday(rs.getString(5));
tc.setCustomerAddress(rs.getString(7));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tc;
}
public int updataCustomer(TCustomer tc){
int ret;
Connection con = null;
ResultSet rs = null;
ret = 0;
PreparedStatement pstmt;
try {
con = ConnectionMgr.getConnection();
String sql="update TCustomer set customer_name=?,customer_birtyday =TO_DATE('"+ tc.getCustomerBirthday()+"','YYYY-MM-DD'),customer_sex=?,customer_address=? where id_number="+tc.getCustomerId()+""+"'";
pstmt = con
.prepareStatement(sql);
System.out.println(tc.getCustomerAddress()+"/////////////////////");
pstmt.setString(1, tc.getCustomerName());
pstmt.setString(2, Character.toString(tc.getCustomerGender()));
pstmt.setString(3, tc.getCustomerAddress());
ret = pstmt.executeUpdate();
System.out.println(ret+"[[[[[[[[[[[[[[[[[[[");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -