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

📄 commondao.java

📁 使用myeclipse进行的项目设计实例
💻 JAVA
字号:
package cn.com.zzrd.easy.bass.common;

import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import cn.com.zzrd.easy.bass.ConnDb;

/**
系统名:物流系统
功能概要: 登录画面的共通处理
完成者:
完成日:
*/
public class CommonDAO {
	
	/**
	 * 取得数据库表中的一个字段
	 * @param sTableName
	 * @param sSectionName
	 * @return 取得的字段list
	 * @throws Exception
	 */
	public List getCommonList(String sTableName, String sSectionName) throws Exception{
		/*变量定义*/
		List list = new ArrayList();
		StringBuffer sqlBuffer = new StringBuffer();
		Statement statement = null;
		ResultSet result = null;
		/*sql*/
		sqlBuffer.append("SELECT DISTINCT \n");
		sqlBuffer.append("       ");
		sqlBuffer.append(sSectionName);
		sqlBuffer.append(" AS SECTIONNAME \n");
		sqlBuffer.append("  FROM \n");
		sqlBuffer.append("       ");
		sqlBuffer.append(sTableName);
		sqlBuffer.append(" WHERE \n");
		sqlBuffer.append(sSectionName);
		sqlBuffer.append(" IS NOT NULL");

		/*处理*/
		try{
			ConnDb.dbOpen();
			statement = ConnDb.conn.createStatement();
			result = statement.executeQuery(sqlBuffer.toString());
			while(result.next()){
				list.add(new String(result.getString("SECTIONNAME")));
			}
		}catch(Exception e){
			throw e;
		}finally{
			ConnDb.dbClose();
			statement.close();
			result.close();
		}
		//返回值
		return list;
	}
	
	/**
	 * 数据字段的存在性check
	 * @param sTableName
	 * @param sSectionName
	 * @param sItemName
	 * @return boolean值
	 * @throws Exception
	 */
	public final static boolean checkItemExistance(String sTableName, String sSectionName, long sItemName) throws Exception{
		/*变量*/
		Statement statement = null;
		ResultSet result = null;
		/* SQL */
		StringBuffer sqlBuffer = new StringBuffer();
		sqlBuffer.append("SELECT \n");
		sqlBuffer.append("       * \n");
		sqlBuffer.append("  FROM ");
		sqlBuffer.append(sTableName);
		sqlBuffer.append(" \n");
		sqlBuffer.append(" WHERE \n ");
		sqlBuffer.append("       ");
		sqlBuffer.append(sSectionName);
		sqlBuffer.append(" = ");
		sqlBuffer.append(sItemName);
		sqlBuffer.append(" \n");
		sqlBuffer.append("  AND \n");
		sqlBuffer.append("      DEL_FLG = 0");
		
		try{
			ConnDb.dbOpen();
			statement = ConnDb.conn.createStatement();
			result = statement.executeQuery(sqlBuffer.toString());
			return result.next();
		} finally {
			ConnDb.dbClose();
			ConnDb.dbClose();
			statement.close();
			result.close();
		}
	}
}

⌨️ 快捷键说明

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