package com.imooc.dao;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.imooc.model.Goddess;
import com.imooc.po.UDFtil;
public class GoddessDao {
public void addGoddess(Goddess g) throws Exception{
Connection conn=UDFtil.getConnection();
String st="insert into imooc_goddess" +
"(user_name,sex,age,birthday,email,mobil," +
"create_user,create_date,update_user,update_date,isdel" +
"values(" +
"?,?,?,?,?,?,?,current_date(),?,current_date(),?)";
PreparedStatement ptm=conn.prepareStatement(st);
ptm.setString(1,g.getUser_name());
ptm.setInt(2, g.getSex());
ptm.setInt(3, g.getAge());
ptm.setDate(4,new Date(g.getBirthday().getTime()));
ptm.setString(5, g.getEmail());
ptm.setString(6, g.getMobile());
ptm.setString(7, g.getCreate_user());
ptm.setString(8, g.getUpdate_user());
ptm.setInt(9, g.getIsdel());
ptm.execute();
}
public void updateGoddess(){
}
public void delGoddess(){
}
public List<Goddess> query() throws Exception{
Connection conn=UDFtil.getConnection();
//3.声明连接数据库,来操作数据库里面的数据
Statement st=conn.createStatement();
//4,通过statement里面的方法来进行数据操作
ResultSet rs=st.executeQuery("select user_name,age from imooc_goddess");
List<Goddess> lg=new ArrayList<Goddess>();
Goddess g=null;
while(rs.next()){
g=new Goddess();
g.setUser_name(rs.getString("user_name"));
g.setAge(rs.getInt("age"));
lg.add(g);
}
return lg;
}
public Goddess get(){
return null;
}
}