package com.rq.txl.model.DAOImplJDBC.dao;
import java.sql.*;
import java.util.*;
import com.rq.txl.model.dto.PersoninfDTO;
import com.rq.txl.model.DAOIfc.PersoninfDAOIfc;
import com.rq.txl.model.dto.*;
/**
*kingbill 2006 3.21 all rights reserved
*��� strutsbook@126.com
*��ݿ���ֱ��l�� ����0.8��
*/
/*
*/
//personinfDAO++++++++++++++++++++++++++++++++++++++++++++++++++
public class PersoninfDAO implements PersoninfDAOIfc{
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/txl";
String username = "root";
String password = "root";
//CreateByDTO------------------------------------------------
public void createPersoninf(PersoninfDTO personinf)
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
String sql="insert into personinf (Id,name,phone,type,shuliang,zb,username) values ("
+ "'" + personinf.getId() + "'" + ","
+ "'" + personinf.getName() + "'" + ","
+ "'" + personinf.getPhone() + "'" + ","
+ "'" + personinf.getType() + "'" + ","
+ personinf.getShuliang() + ","
+ "'" + personinf.getZb() + "'" + ","
+ "'" + personinf.getUsername() + "'"
+")";
stmt = con.createStatement();
stmt.execute(sql);
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}
}
//UpdateByDTO------------------------------------------------
public void updatePersoninf(PersoninfDTO personinf)
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
String sql = "update personinf set "
+ "name ='" + personinf.getName() + "',"
+ "phone ='" + personinf.getPhone() + "',"
+ "type ='" + personinf.getType() + "',"
+ "shuliang =" +personinf.getShuliang() + ","
+ "zb ='" + personinf.getZb() + "',"
+ "username ='" + personinf.getUsername() + "'"
+ " where Id = '" + personinf.getId() + "'"
;
stmt = con.createStatement();
stmt.executeUpdate(sql);
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}
}
//UpdateByDTOs------------------------------------------------
public void updatePersoninfs(Vector personinfs)
{
Iterator it = personinfs.iterator();
while(it.hasNext())
{
PersoninfDTO personinf = (PersoninfDTO)it.next();
updatePersoninf(personinf);
}
}
//RemoveByPrimaryKey------------------------------------------------
public void removeByPrimaryKey(java.lang.String _Id)
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
String sql = "delete from personinf where Id = '" + _Id + "'";
stmt = con.createStatement();
stmt.execute(sql);
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
}
}
//RemoveByDTO------------------------------------------------
public void removePersoninf(PersoninfDTO personinf)
{
removeByPrimaryKey(personinf.getId());
}
//RemoveByDTOs------------------------------------------------
public void removePersoninfs(Vector personinfs)
{
Iterator it = personinfs.iterator();
while(it.hasNext())
{
PersoninfDTO personinf = (PersoninfDTO)it.next();
removePersoninf(personinf);
}
}
//findByPrimaryKey------------------------------------------------
public PersoninfDTO findByPrimaryKey(java.lang.String _Id)
{
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
PersoninfDTO personinf = new PersoninfDTO();
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
String sql = "select * from personinf where Id = '" + _Id + "'";
rs = stmt.executeQuery(sql);
while(rs.next())
{
personinf.setId(rs.getString("Id"));
personinf.setName(rs.getString("name"));
personinf.setPhone(rs.getString("phone"));
personinf.setType(rs.getString("type"));
personinf.setShuliang(new Integer(rs.getInt("shuliang")));
personinf.setZb(rs.getString("zb"));
personinf.setUsername(rs.getString("username"));
}
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
return personinf;
}
}
public List findByType(String _type) {
List<PersoninfDTO> ls=new ArrayList<PersoninfDTO>();
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
PersoninfDTO personinf = null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
String sql = "select * from personinf where type = '" + _type + "'order by shuliang desc";
rs = stmt.executeQuery(sql);
while(rs.next())
{
personinf = new PersoninfDTO();
personinf.setId(rs.getString("Id"));
personinf.setName(rs.getString("name"));
personinf.setPhone(rs.getString("phone"));
personinf.setType(rs.getString("type"));
personinf.setShuliang(new Integer(rs.getInt("shuliang")));
personinf.setZb(rs.getString("zb"));
personinf.setUsername(rs.getString("username"));
ls.add(personinf);
}
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
return ls;
}
}
public List findByUsername(String _username) {
List<PersoninfDTO> ls=new ArrayList<PersoninfDTO>();
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
PersoninfDTO personinf = null;
try{
Class.forName(driver);
con = DriverManager.getConnection(url,username,password);
stmt = con.createStatement();
String sql = "select * from personinf where username = '" + _username + "'order by shuliang desc";
rs = stmt.executeQuery(sql);
while(rs.next())
{
personinf = new PersoninfDTO();
personinf.setId(rs.getString("Id"));
personinf.setName(rs.getString("name"));
personinf.setPhone(rs.getString("phone"));
personinf.setType(rs.getString("type"));
personinf.setShuliang(new Integer(rs.getInt("shuliang")));
personinf.setZb(rs.getString("zb"));
personinf.setUsername(rs.getString("username"));
ls.add(personinf);
}
}
catch(Exception sqlex1)
{
sqlex1.printStackTrace();
}
finally
{
if (con != null) {
try {
con.close();
}
catch(SQLException sqlex2)
{
sqlex2.printStackTrace();
}
}
return ls;
}
}
public List findByname(String _name) {
List<PersoninfDTO> ls=new ArrayList<Pers