package com.flower.www.persistence;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.omg.CORBA.Request;
import com.flower.
www.domian.CustomerInfo;
public class CustomerInfoDao {
private Connection dataConnection;
final static String selectStr = "select * from customerinfo";
final static String insertStr = "insert into customerinfo(customerName,age,sex,date,describe,money,realMoney,moreMoney,addContent,mobile1,mobile2,phone,weight,high,birthday,qq,email,range,caiKuo,caiPen,shuiBan,xiangKuang,xiaoJian,ckFlag,cpFlag,sbFlag,xkFlag,xjFlag,good1,good2,good3,good4,good5,g1,g2,g3,g4,g5)" +
"value(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
final static String updateStr = "update customerinfo set ";
final static String deleteStr = "delete customerinfo where ";
final static String findStr = "select * from customerinfo where customerName = ?";
final static String findStr2Test = "select * from customerinfo where age = ?";
public CustomerInfoDao() {
DataBaseConnect dataBaseConnect = null;
try {
dataBaseConnect = new DataBaseConnect();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in CustomerInfo() constructor1 : " + e.getMessage());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in CustomerInfo() constructor : " + e.getMessage());
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in CustomerInfo() constructor: " + e.getMessage());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in CustomerInfo() constructor: " + e.getMessage());
}
dataConnection = dataBaseConnect.dataConnection;
}
public int inserCustomerInfo(CustomerInfo customerInfo) throws Exception {
try {
PreparedStatement statement = dataConnection.prepareStatement(insertStr);
String date = customerInfo.getDate();
String birthday = customerInfo.getBirthday();
System.out.println(date);
System.out.println(birthday);
statement.setString(1, customerInfo.getCustomerName());
statement.setInt(2, customerInfo.getAge());
statement.setString(3, customerInfo.getSex());
statement.setDate(4, customerInfo.string2Date(date));
statement.setString(5, customerInfo.getDescribe());
statement.setInt(6, customerInfo.getMoney());
statement.setInt(7, customerInfo.getRealMoney());
statement.setInt(8, customerInfo.getMoreMoney());
statement.setString(9, customerInfo.getAddContent());
statement.setString(10, customerInfo.getMobile1());
statement.setString(11, customerInfo.getMobile2());
statement.setString(12, customerInfo.getPhone());
statement.setInt(13, customerInfo.getWeight());
statement.setInt(14, customerInfo.getHigh());
statement.setDate(15, customerInfo.string2Date(birthday));
statement.setString(16, customerInfo.getQq());
statement.setString(17, customerInfo.getEmail());
statement.setInt(18, customerInfo.getRange());
statement.setString(19, customerInfo.getCaiKuo());
statement.setString(20, customerInfo.getCaiPen());
statement.setString(21, customerInfo.getShuiBan());
statement.setString(22, customerInfo.getXiangKuang());
statement.setString(23, customerInfo.getXiaoJian());
statement.setInt(24, customerInfo.getCkFlag());
statement.setInt(25, customerInfo.getCpFlag());
statement.setInt(26, customerInfo.getSbFlag());
statement.setInt(27, customerInfo.getXkFlag());
statement.setInt(28, customerInfo.getXjFlag());
statement.setString(29, customerInfo.getGood1());
statement.setString(30, customerInfo.getGood2());
statement.setString(31, customerInfo.getGood3());
statement.setString(32, customerInfo.getGood4());
statement.setString(33, customerInfo.getGood5());
statement.setInt(34, customerInfo.getG1());
statement.setInt(35, customerInfo.getG2());
statement.setInt(36, customerInfo.getG3());
statement.setInt(37, customerInfo.getG4());
statement.setInt(38, customerInfo.getG5());
statement.execute();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in inserCustomerInfo() : " + e.getMessage());
}
return 1;
}
public CustomerInfo findCustomerInfo(CustomerInfo customerInfo) {
CustomerInfo acustomerInfo = new CustomerInfo();
System.out.println("CustomerInfoDao"+customerInfo.getCustomerName());
System.out.println("CustomerInfoDao"+customerInfo.getAge());
try {
PreparedStatement statement = dataConnection.prepareStatement(findStr2Test);
// statement.setString(1, customerInfo.getCustomerName());
statement.setInt(1, customerInfo.getAge());
ResultSet result = statement.executeQuery();
while(result.next()) {
acustomerInfo.setId(new Integer(result.getInt("id")));
acustomerInfo.setCustomerName(result.getString("customerName"));
acustomerInfo.setAge(result.getInt("age"));
acustomerInfo.setSex(result.getString("sex"));
acustomerInfo.setDate(result.getString("date"));
acustomerInfo.setDescribe(result.getString("describe"));
acustomerInfo.setMoney(result.getInt("money"));
acustomerInfo.setRealMoney(result.getInt("realMoney"));
acustomerInfo.setMoreMoney(result.getInt("moreMoney"));
acustomerInfo.setAddContent(result.getString("addContent"));
acustomerInfo.setMobile1(result.getString("mobile1"));
acustomerInfo.setMobile2(result.getString("Mobile2"));
acustomerInfo.setPhone(result.getString("phone"));
acustomerInfo.setWeight(result.getInt("weight"));
acustomerInfo.setHigh(result.getInt("high"));
acustomerInfo.setBirthday(result.getString("birthday"));
acustomerInfo.setQq(result.getString("qq"));
acustomerInfo.setEmail(result.getString("email"));
acustomerInfo.setRange(result.getInt("range"));
acustomerInfo.setCaiKuo(result.getString("caiKuo"));
acustomerInfo.setCaiPen(result.getString("caiPen"));
acustomerInfo.setShuiBan(result.getString("shuiBan"));
acustomerInfo.setXiangKuang(result.getString("xiangKuang"));
acustomerInfo.setXiaoJian(result.getString("xiaoJian"));
acustomerInfo.setCkFlag(result.getInt("ckFlag"));
acustomerInfo.setCpFlag(result.getInt("cpFlag"));
acustomerInfo.setSbFlag(result.getInt("sbFlag"));
acustomerInfo.setXkFlag(result.getInt("xkFlag"));
acustomerInfo.setXjFlag(result.getInt("xjFlag"));
acustomerInfo.setGood1(result.getString("good1"));
acustomerInfo.setGood2(result.getString("good2"));
acustomerInfo.setGood3(result.getString("good3"));
acustomerInfo.setGood4(result.getString("good4"));
acustomerInfo.setGood5(result.getString("good5"));
acustomerInfo.setG1(result.getInt("g1"));
acustomerInfo.setG2(result.getInt("g2"));
acustomerInfo.setG3(result.getInt("g3"));
acustomerInfo.setG4(result.getInt("g4"));
acustomerInfo.setG5(result.getInt("g5"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error Trace in findCustomerInfo() : " + e.getMessage());
}
return acustomerInfo;
}
}