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

📄 pcdaoimpl.java

📁 swing+jdbc+sqlserver2000的小型网吧系统
💻 JAVA
字号:
package org.itstar.netbar.dao.impl;

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

import org.itstar.netbar.bean.PCBean;
import org.itstar.netbar.dao.IPCDao;
import org.itstar.netbar.utils.ConnectDB;

public class PCDaoImpl implements IPCDao
{

	public int delete(String pcNum) {
		String strSQL="delete from PC where pcNum='"+pcNum+"'";
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}

	public int insert(PCBean pcBean) {
		String strSQL="insert into PC values('"+pcBean.getPcNum()+"','"
		                                     +pcBean.getPcType()+"','"
		                                     +pcBean.getPcState()+"')";
//		System.out.println(strSQL);
//		System.exit(0);
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}

	public List query(Map map) {
		String strSQL;
		Statement stmt=null;
		strSQL="select * from PC where 1=1";
		
		if(map.get("pcNum")!=null)
			strSQL=strSQL+" and pcNum='"+map.get("pcNum")+"'";
		if(map.get("pcType")!=null)
			strSQL=strSQL+" and pcType='"+map.get("pcType")+"'";
		if(map.get("pcState")!=null)
			strSQL=strSQL+" and pcState='"+map.get("pcState")+"'";
		
		ResultSet rs=null;
		List list=new ArrayList();
		try {
			stmt=ConnectDB.getConn().createStatement();
			rs=stmt.executeQuery(strSQL);
			while(rs.next())
			{
				PCBean pcBean=new PCBean();
				pcBean.setPcNum(rs.getString(1));
				pcBean.setPcType(rs.getString(2));
				pcBean.setPcState(rs.getString(3));
				list.add(pcBean);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public List queryAll() {
		String strSQL;
		Statement stmt=null;
		strSQL="select * from PC where 1=1";

		ResultSet rs=null;
		List list=new ArrayList();
		try {
			stmt=ConnectDB.getConn().createStatement();
			rs=stmt.executeQuery(strSQL);
			while(rs.next())
			{
				PCBean pcBean=new PCBean();
				pcBean.setPcNum(rs.getString(1));
				pcBean.setPcType(rs.getString(2));
				pcBean.setPcState(rs.getString(3));
				list.add(pcBean);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	public int update(PCBean pcBean) {
		String strSQL="update PC set pcType='"+pcBean.getPcType()+"',"
		                          +"pcState='"+pcBean.getPcState()
		                          +"' where pcNum='"+pcBean.getPcNum()+"'";
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}

	public int updatePCState(String pcState, String pcNum) {
		String strSQL="update PC set pcState='"+pcState+"' where pcNum='"+pcNum+"'";
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}

	public int updatePCType(String pcType, String pcNum) {
		String strSQL="update PC set pcType='"+pcType+"' where pcNum='"+pcNum+"'";
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}

	public int updatePCStateReset() {
		String strSQL="update PC set pcState='0' where pcState='1'";
		int count=0;
		try {
			Statement stmt=ConnectDB.getConn().createStatement();
			count=stmt.executeUpdate(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return count;
	}
}

⌨️ 快捷键说明

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