package com.shimeng.dao;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import com.shimeng.dao.interfaces.ILiziDao;
import com.shimeng.vo.LiziVo;
import com.shimeng.mappings.LiziVoMapping;
import java.sql.Types;
public class LiziDao implements ILiziDao {
@SuppressWarnings("unused")
private DataSource dataSource;
private JdbcTemplate jt;
public List<LiziVo> testDataBase() {
String sql = "select * from test_table";
List<LiziVo> resultList = (List<LiziVo>)jt.query(sql, new LiziVoMapping());
return resultList;
}
public List<LiziVo> deleteDataBase(String name) {
String sql = "delete from test_table where name='"+name+"'";
this.jt.update(sql);
return testDataBase();
}
public void setDataSource(DataSource dataSource) {
this.jt = new JdbcTemplate(dataSource);
}
@Override
public List<LiziVo> addDataBase(LiziVo svo) {
String sql = "insert into test_table (name,id,password,xuehao) value (?,?,?,?)";
this.jt.update(sql, new Object[]{svo.getName(), svo.getId(), svo.getPassword(), svo.getXuehao()}, new int[]{Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR});
return testDataBase();
}
public List<LiziVo> alterDataBase(LiziVo svo) {
String sql = "update test_table set id ='"+svo.getId()+"', password ='"+svo.getPassword()+"', xuehao ='"+svo.getXuehao()+"' where name = '"+svo.getName()+"'";
//this.jt.update(sql, new Object[]{svo.getName(), svo.getId(), svo.getPassword(), svo.getXuehao()}, new int[]{Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR});
this.jt.update(sql);
//System.out.println(svo.getId());
return testDataBase();
}
//public String updateDataBase(ShujuVo svo) {
//String sql = "update login_table set password ='"+svo.getPassword()+"' where name = '"+svo.getName()+"'";
//this.jt.update(sql);
//System.out.println(svo.getUsername());
// return "success";
// }
@SuppressWarnings("unchecked")
public List<LiziVo> chaxunDataBase(LiziVo svo) {
// TODO Auto-generated method stub
String sql ="select * from test_table where name='"+svo.getName()+"'";
List<LiziVo> resultList = (List<LiziVo>)jt.query(sql, new LiziVoMapping());
return resultList;
}
}