⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userinfosave.java

📁 基于Struts的电子银行系统
💻 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);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -