package com.gw.bookstroe.dao.impl;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import com.gw.bookstroe.dao.Userdao;
import com.gw.bookstroe.domain.User;
import com.gw.bookstroe.utils.C3P0Utils;
public class Userdaoimpl implements Userdao {
QueryRunner runner = new QueryRunner(C3P0Utils.getDataSource());
@Override
public User findUser(String username, String password) {
String sql="SElECt * from user where username=? and password=?";
User user =null;
try{
user =(User)runner.query(sql, new BeanHandler
}catch(SQLException e){
e.printStackTrace();
}
return user;
}
@Override
public boolean insert(User user) {
String sql="insert into user(username,password,gender,email,telephone,introduce,activeCode) values(?,?,?,?,?,?,?)";
int num =0;
try {
num = runner.update(sql, user.getUsername(),user.getPassword()
,user.getGender(),user.getEmail(),user.getTelephone(),user.getIntroduce()
,user.getActiveCode());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(num>0){return true;}
return false;
}
@Override
public User findname(String username) {
String sql="SElECT * from user where username=?";
User user =null;
try{
user =(User)runner.query(sql, new BeanHandler
}catch(SQLException e){
e.printStackTrace();
}
return user;
}
@Override
public boolean editUser(String username, String repassword, String telephone, String email) {
String sql="update user set PASSWORD=? , telephone=? ,email=? where username=?";
int num =0;
try {
num = runner.update(sql,repassword,telephone,email,username);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(num>0){return true;}
return false;
}
}



