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

📄 tb_user_mstdaoimpl.java

📁 一个完整的代码管理系统的源代码
💻 JAVA
字号:
/*
 * Copyright (c) 2008-2010 Tanming1003 Inc.
 * All rights reserved.
 * 
 * tanming1003<tanming1003@163.com>
 * 
 * 
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions 
 * are met:
 * 
 * Redistributions of source code must retain the above copyright 
 * notice, this list of conditions and the following disclaimer. 
 * Redistributions in binary form must reproduce the above copyright 
 * notice, this list of conditions and the following disclaimer in the 
 * documentation and/or other materials provided with the distribution. 
 * Neither the name of tanming1003 nor the names of its contributors 
 * may be used to endorse or promote products derived from this 
 * software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 */
package hunnu.edu.cn.product.common.db.dao.implement;

import java.math.BigDecimal;
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 hunnu.edu.cn.product.common.db.DBProcess;
import hunnu.edu.cn.product.common.db.DBUtil;
import hunnu.edu.cn.product.common.db.DBWrapper;
import hunnu.edu.cn.product.common.db.dao.TB_USER_MSTDao;
import hunnu.edu.cn.product.common.db.model.TB_USER_MST;

/**
 * @author tanming1003@163.com
 * @date 2008-10-16
 * @time 下午12:31:43
 * @project_name Product
 * @package_name hunnu.edu.cn.product.common.db.dao.implement
 * @file_name    TB_USER_MSTDaoImpl.java
 * @version      1.0
 */
public class TB_USER_MSTDaoImpl implements TB_USER_MSTDao
{
   
	protected TB_USER_MSTDaoImpl()
	{
		super();
	}
	/**
     * 向数据库TB_USER_MST表增加一条记录
     */
	public boolean add(TB_USER_MST user)
	{
		DBProcess process=new DBWrapper();
		Connection connection=null;
		String countSql="select user_id from TB_USER_MST order by user_id";
		try
		{
			int maxId;
			connection=process.getConnection();
			PreparedStatement statement=connection.prepareStatement(countSql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
            ResultSet resultSet=statement.executeQuery();
            if(resultSet.last())
            	maxId=resultSet.getInt(1);
            else
            	maxId=0;
            maxId++;
            user.setUser_id(maxId);
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try {
				process.closeConnection(connection);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return DBUtil.add(user);
	}
	
    /**
     * 得到数据库TB_USER_MST中所有记录
     */
	@SuppressWarnings("unchecked")
	public List<TB_USER_MST> getAll()
	{
		return DBUtil.getAll(new TB_USER_MST());
	}
    
	/**
	 * 根据key值查询数据库表TB_USER_MST
	 */
	public TB_USER_MST getByID(int id)
	{
		BigDecimal ids[]={new BigDecimal(id)};
		return (TB_USER_MST) DBUtil.get(new TB_USER_MST(),ids);
	}
	
	public List<TB_USER_MST> getByName(String userName)
	{
		 String sql="select * from TB_USER_MST where user_login like"+"'"+userName+"'";
		 DBWrapper dbwrapper=new DBWrapper();
         Connection connection=null;
		 try
         {
             connection=dbwrapper.getConnection();
             PreparedStatement statement=connection.prepareStatement(sql);
             ResultSet rs=statement.executeQuery();
             List<TB_USER_MST> users=new ArrayList<TB_USER_MST>();
             while(rs.next())
             {
            	 TB_USER_MST user=new TB_USER_MST();
            	 user.setUser_id(rs.getInt("user_id"));
            	 user.setUser_name(rs.getString("user_name"));
            	 user.setUser_password(rs.getString("user_password"));
            	 user.setUser_flg(rs.getString("user_flg"));
            	 user.setUser_email(rs.getString("user_email"));
            	 user.setUser_group_id(rs.getString("user_group_id"));
            	 user.setUser_login(rs.getString("user_login"));
            	 user.setUpd_user_id(rs.getInt("upd_user_id"));
            	 user.setUpd_ymdhms(rs.getTimestamp("upd_ymdhms"));
            	 users.add(user);
             }
             return users;
        }
         catch(Exception e)
         {
        	  e.printStackTrace();
        	 
         }
         finally
         {
        	try
			{
				dbwrapper.closeConnection(connection);
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
         }
         return null;
	}
    
	/**
	 * 删除数据库表中的几条记录
	 */
	public boolean removes(int[] list)
	{
		TB_USER_MST users[]=new TB_USER_MST[list.length];
		for(int i=0;i<users.length;i++)
		{
			users[i]=new TB_USER_MST();
			users[i].setUser_id(list[i]);
		}
		return DBUtil.remove(users);
	}
    
	/**
	 * 更新数据库中TB_USER_MST的一条记录
	 */
	public int update(TB_USER_MST user)
	{
		return DBUtil.update(user);
	}
    
	/**
	 * 删除数据库中TB_USER_MST表中所有记录
	 */
	public boolean removeAll()
	{
		return  DBUtil.remove(new TB_USER_MST());
	}

}

⌨️ 快捷键说明

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