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

📄 oracletchargedao.java

📁 jsp/servlet中国移动模拟收费系统
💻 JAVA
字号:
package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javabean.TCharge;

public class OracleTChargeDAO implements TChargeDAO{
	private final String UPDATE_AN_TCHARGE ="update tcharge set charge=? where charge_code=?";
	private final String GET_CHARGE_MONEY = "select charge from tcharge where charge_code=?";
	private final String GET_ALL_TCHARGE = "select * from tcharge";
	
	public boolean updateTCharge(TCharge tcharge){
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean tmp = true;
		try{
			conn = OracleDAOFactory.getConnection();
			pstmt = conn.prepareStatement(UPDATE_AN_TCHARGE);
			System.out.println("%%$$%%%  tcharge.getChargeCode() :  " + tcharge.getChargeCode());
			System.out.println("%%$$%%%  tcharge.getChargeMoney() :  " + tcharge.getChargeMoney());
			
			pstmt.setString(2, tcharge.getChargeCode());
			pstmt.setFloat(1, tcharge.getChargeMoney());
			
			int result = pstmt.executeUpdate();
			if(result!=1){
				tmp = false;
			}
		}catch(SQLException e){
			tmp = false;
			e.printStackTrace();
		}finally{
			OracleDAOFactory.closeStatement(pstmt);
			OracleDAOFactory.closeConnection(conn);
		}
		return tmp;
	}
	
	
	public float getChargeMoney(TCharge tcharge){
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		float money = 0;
		try{
		conn = OracleDAOFactory.getConnection();
		pstmt = conn.prepareStatement(GET_CHARGE_MONEY);
		pstmt.setString(1,tcharge.getChargeCode());
		rs = pstmt.executeQuery();		
		if(rs.next()){
			System.out.println("CHARGE_MONEY"+Float.parseFloat(rs.getString("charge")));
			money = Float.parseFloat(rs.getString("charge"));
			return money;
		}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			OracleDAOFactory.closeResultSet(rs);
			OracleDAOFactory.closeStatement(pstmt);
			OracleDAOFactory.closeConnection(conn);
		}
		return money;
	}
	
	public List getAllTCharge(){
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		TCharge tcharge = null;
		try{
			conn = OracleDAOFactory.getConnection();
			pstmt = conn.prepareStatement(GET_ALL_TCHARGE);
			rs = pstmt.executeQuery();
			ArrayList tcharges = new ArrayList();
			while(rs.next()){
				tcharge = new TCharge();
				tcharge.setChargeCode(rs.getString("charge_code"));
				tcharge.setChargeName(rs.getString("charge_name"));
				tcharge.setChargeMoney(rs.getFloat("charge"));
				tcharges.add(tcharge);
			}
			return tcharges;
		}catch(SQLException e){
			e.printStackTrace();
			return null;
		}finally{
			OracleDAOFactory.closeResultSet(rs);
			OracleDAOFactory.closeStatement(pstmt);
			OracleDAOFactory.closeConnection(conn);
		}
	}
}

⌨️ 快捷键说明

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