【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“UserInfoSave.java”一文,供大家参考学习
/*
* Created on 2005-7-24
*
*/
package banksystem.business;
/**
* @author 曲本盛
*
* TODO Struts 项目实践
*/
import java.sql.*;
import javax.sql.*;
import banksystem.PO.Customer;
import banksystem.Constants;
import banksystem.GetCurrentTime;
public class UserInfoSave {
/**
* @param dataSource 数据源.
* @param customer 要保存的用户信息.
*/
public void save(DataSource dataSource,Customer customer) throws SQLException,Exception {
Connection con = null;
CallableStatement call = null;
PreparedStatement stat = null;
try{
con = dataSource.getConnection();
call = con.prepareCall(Constants.PROC_CREATE_CUSTOMERID);
call.registerOutParameter(2,Types.CHAR);
call.setString(1,"C");
call.executeUpdate();
String customerID = call.getString(2);
call.close();
//此处定要去空格,不去空格则会带有很多回车换行符,造成新用户注册后交易时报错(不能比较nText或Image对象)
customer.setAccountID(customerID.trim());
customer.setOpenDate(GetCurrentTime.getCurrentTime());
stat = con.prepareStatement(Constants.SQL_CUSTOMER_INSERT);
stat.setString(1,customerID);
stat.setString(2,customer.getUserName());
stat.setString(3,customer.getSex());
stat.setString(4,customer.getLoginPass());
stat.setString(5,customer.getTradePass());
stat.setString(6,customer.getID());
stat.setString(7,customer.getPhone());
stat.setString(8,customer.getAddr());
stat.setString(9,customer.getOpenDate());
stat.setDouble(10,customer.getBalance().doubleValue());
stat.setString(11,customer.getStatus());
int rows = stat.executeUpdate();
if(rows==0){
throw new SQLException(Constants.INSERT_FAILED);
}
}
catch(SQLException e){
//e.printStackTrace();
e.fillInStackTrace();
throw e;
}
finally{
try{
if(con!=null){
con.close();
}
if(stat!=null){
stat.close();
}
}
catch(SQLException e){
e.fillInStackTrace();
throw e;
}
}
}
/**
* @param dataSource 数据源.
* @param customer 要保存的用户信息.
*/
public void update(DataSource dataSource,Customer customer) throws SQLException {
Connection con = null;
PreparedStatement stat = null;
try{
con = dataSource.getConnection();
stat = con.prepareStatement(Constants.SQL_CUSTOMER_UPDATE);
stat.setString(1,customer.getUserName());
stat.setString(2,customer.getSex());
stat.setString(3,customer.getLoginPass());
stat.setString(4,customer.getTradePass());
stat.setString(5,customer.getID());
stat.setString(6,customer.getPhone());
stat.setString(7,customer.getAddr());
stat.setString(8,customer.getAccountID());
int rows = stat.executeUpdate();
if(rows==0){
throw new SQLException(Constants.INSERT_FAILED);
}
}
catch(SQLException e){
e.fillInStackTrace();
throw e;
}
finally{
try{
if(con!=null){
con.close();
}
if(stat!=null){
stat.close();
}
}
catch(SQLException e){
throw new SQLException(Constants.DATABASE_CLOSE_FAILED);
}
}
}
}
上一篇:
UserInfoPage.java
下一篇:
她要是喜欢我