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

📄 dictionarydao.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
字号:
package edu.yinhe.mis.model;

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


import edu.yinhe.mis.dto.DictionaryDTO;
import edu.yinhe.mis.vo.DictionaryVO;
import edu.yinhe.system.model.BaseDAO;
//import edu.yinhe.system.model.IBaseDAO;
/**
 * @author 马少华
 */
public class DictionaryDAO extends BaseDAO {

	/**
	 * @author 马少华 <p>
	 * 此方法是用来删除一条或多条数据
	 * @param obj 传入DictionaryDTO对象
	 *@throws SQLException
	 * @return 返回一个BOOLEAN值			
	 */
	public Object delete(Object obj) throws SQLException {
		String did = (String)obj;
		PreparedStatement ps = null;
		boolean flag = false;
		int isok = 0;
		String sql = null;
		try {
			if(did!=null){
				sql = "DELETE FROM DICTIONARY WHERE ID=? || SCOPE=? || PID=?";
				ps = conn.prepareStatement(sql);
				String []str = did.split("_");
				for(int i=0;i<str.length;i++){
					if(str[i]!=null && !"".equals(str[i])){
						ps.setInt(1, Integer.parseInt(str[i]));
						ps.setString(2, str[i]);
						ps.setString(3, str[i]);
						isok = ps.executeUpdate();
					}
				}
				if(isok!=-1){
					flag = true;
				}
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			sql = null;
		}
		return flag;
	}

	public Object find() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Object find(Object arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Object findAll() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * @author 马少华 <p>
	 * 用来根据任何条件查询数据
	 * @param obj 传入DictionaryDTO对象
	 *@throws SQLException
	 * @return 返回LIST的集合			
	 */
	public Object findAll(Object obj) throws SQLException {
		DictionaryDTO dictionaryDto = (DictionaryDTO)obj;
		String sql = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List list = new ArrayList();
		DictionaryVO dictionaryVO = null;
		StringBuffer sb = new StringBuffer("SELECT * FROM DICTIONARY WHERE 1=1");
		Integer integer = new Integer(0);
		Object[] objs = new Object[2];
		integer = getCount(dictionaryDto);
		try {
			if(dictionaryDto.getId()!=null && !"".equals(dictionaryDto.getId())){
				sb.append(" AND ID='"+dictionaryDto.getId()+"'");	
			}
			if(dictionaryDto.getName()!=null && !"".equals(dictionaryDto.getName())){
				sb.append(" AND NAME like '%"+dictionaryDto.getName().trim()+"%'");
			}
			if(dictionaryDto.getValue()!=null && !"".equals(dictionaryDto.getValue())){
				sb.append(" AND VALUE='"+dictionaryDto.getValue()+"'");
			}
			if(dictionaryDto.getPid()!=null && !"".equals(dictionaryDto.getPid())){
				sb.append(" AND PID='"+dictionaryDto.getPid()+"'");
			}
			if(dictionaryDto.getScope()!=null && !"".equals(dictionaryDto.getScope())){
				sb.append(" AND SCOPE='"+dictionaryDto.getScope()+"'");
			}
			if(dictionaryDto.getCurrentPage()!=null && !"".equals(dictionaryDto.getCurrentPage()) && dictionaryDto.getRowPerPage()!=null && !"".equals(dictionaryDto.getRowPerPage())){
				int i = (Integer.parseInt(dictionaryDto.getCurrentPage())-1)*Integer.parseInt(dictionaryDto.getRowPerPage());
				sb.append(" ORDER BY ID DESC LIMIT "+i+","+dictionaryDto.getRowPerPage());
			}
			sql = sb.toString();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()){
				dictionaryVO = new DictionaryVO();
				dictionaryVO.setId(rs.getString("id"));
				dictionaryVO.setName(rs.getString("name"));
				dictionaryVO.setValue(rs.getString("value"));
				dictionaryVO.setPid(rs.getString("pid"));
				dictionaryVO.setScope(rs.getString("scope"));
				dictionaryVO.setCreateTime(rs.getString("createTime").substring(0, 11));
				list.add(dictionaryVO);
			}
			objs[0]=list;
			objs[1]=integer;
		} catch (RuntimeException e) {
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			if(rs!=null)rs.close();
			sql = null;
			sb = null;
			dictionaryDto = null;
		}
		
		return objs;
	}
	/**
	 * 
	 */
	public Object findById(Object arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public Object findByObject(Object arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * @author 马少华 <p>
	 * 用来根据任何条件查询出数据的记录
	 * @param obj 传入DictionaryDTO对象
	 *@throws SQLException
	 * @return 返回INT类型的值			
	 */
	public int getCount(Object obj) throws SQLException {
		DictionaryDTO dictionaryDto = (DictionaryDTO)obj;
		String sql = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		Integer integer=new Integer(0);
		StringBuffer sb = new StringBuffer("SELECT COUNT(*) result FROM DICTIONARY WHERE 1=1");
		try {
			if(dictionaryDto.getId()!=null && !"".equals(dictionaryDto.getId())){
				sb.append(" AND ID='"+dictionaryDto.getId()+"'");	
			}
			if(dictionaryDto.getName()!=null && !"".equals(dictionaryDto.getName())){
				sb.append(" AND NAME like '%"+dictionaryDto.getName().trim()+"%'");
			}
			if(dictionaryDto.getValue()!=null && !"".equals(dictionaryDto.getValue())){
				sb.append(" AND VALUE='"+dictionaryDto.getValue()+"'");
			}
			if(dictionaryDto.getPid()!=null && !"".equals(dictionaryDto.getPid())){
				sb.append(" AND PID='"+dictionaryDto.getPid()+"'");
			}
			if(dictionaryDto.getScope()!=null && !"".equals(dictionaryDto.getScope())){
				sb.append(" AND SCOPE='"+dictionaryDto.getScope()+"'");
			}
			sql = sb.toString();
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			if(rs.next()){
				integer = new Integer(rs.getInt("result"));
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			if(rs!=null)rs.close();
			sql = null;
			sb = null;
			
		}
		
		return integer;
	}

	public Object getMaxId(Object arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}
	/**
	 * @author 马少华 <p>
	 * 用来插入数据
	 * @param obj 传入DictionaryDTO对象
	 *@throws SQLException
	 * @return 返回一个BOOLEAN型的值		
	 */
	public Object insert(Object obj) throws SQLException {
		DictionaryDTO dictionaryDto = null;
		String sql = null;
		PreparedStatement ps = null;
		boolean flag = false;
		int isok = 0;
		try {
			dictionaryDto = (DictionaryDTO) obj;
			sql = "INSERT INTO DICTIONARY(NAME,VALUE,SCOPE,PID) VALUES(?,?,?,?);";
			ps = conn.prepareStatement(sql);
			ps.setString(1, dictionaryDto.getName());
			ps.setString(2, dictionaryDto.getValue());
			ps.setString(3, dictionaryDto.getScope());
			ps.setString(4, dictionaryDto.getPid());
			isok = ps.executeUpdate();
			conn.commit();
			if(isok!=-1){
				flag = true;
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			sql = null;
			dictionaryDto = null;
		}
		return flag;
	}
	
	/**
	 * @author 马少华 <p>
	 * 用来修改指定数据
	 * @param obj 传入DictionaryDTO对象
	 *@throws SQLException
	 * @return 返回一个BOOLEAN型的值		
	 */
	
	public Object update(Object obj) throws SQLException {
		DictionaryDTO dictionaryDto = (DictionaryDTO)obj;
		String sql = null;
		PreparedStatement ps = null;
		boolean flag = false;
		try {
			sql = "UPDATE DICTIONARY SET VALUE=?,NAME=? WHERE ID=?";
			ps = conn.prepareStatement(sql);
			ps.setString(1,dictionaryDto.getValue());
			ps.setString(2, dictionaryDto.getName());
			ps.setInt(3, Integer.parseInt(dictionaryDto.getId()));
			int i = ps.executeUpdate();
			if(i!=-1){
				flag = true;
			}
		} catch (RuntimeException e) {
			e.printStackTrace();
		}finally{
			if(ps!=null)ps.close();
			sql = null;
			
		}
		return flag;
	}

}

⌨️ 快捷键说明

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