?? pcdaoimpl.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 + -