/**
*
*/
package org.enilu.ibatis.dao.impl;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;
import org.enilu.ibatis.dao.IStudentDAO;
import org.enilu.ibatis.vo.Student;
import com.ibatis.sqlmap.client.SqlMapClient;
/**
* @author ZT
*
*/
public class IStudentDAOImpl implements IStudentDAO {
private static SqlMapClient sqlMapClient;
static {
try {
// 取得一个输出流
Reader reader = com.ibatis.common.resources.Resources
.getResourceAsReader("SqlMapConfig.xml");
// 取得sqlMapClient
sqlMapClient = com.ibatis.sqlmap.client.SqlMapClientBuilder
.buildSqlMapClient(reader);
// 关闭输出流
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*
* (non-Javadoc)
*
* @see org.enilu.ibatis.dao.IStudentDAO#deleteById(int)
*/
public boolean deleteById(int sid) throws Exception {
// 大于0表示删除成功,
if (sqlMapClient.delete("deletestudentbyid", sid) > 0) {
return true;
}
return false;
}
/*
* (non-Javadoc)
*
* @see org.enilu.ibatis.dao.IStudentDAO#doCreate(org.enilu.ibatis.vo.Student)
*/
public boolean doCreate(Student student) throws Exception {
boolean flag = true;
if (sqlMapClient.insert("insertstudent", student) != null) {
flag = false;
}
return flag;
}
/*
* (non-Javadoc)
*
* @see org.enilu.ibatis.dao.IStudentDAO#findAll()
*/
public List<Student> findAll() throws Exception {
List all = null;
try {
all = sqlMapClient.queryForList("selectAllStudent");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return all;
}
/*
* (non-Javadoc)
*
* @see org.enilu.ibatis.dao.IStudentDAO#findById(int)
*/
public Student findById(int sid) {
Student student = null;
try {
student = (Student) sqlMapClient.queryForObject("selectById", sid);
} catch (SQLException e) {
e.printStackTrace();
}
return student;
}
/*
* (non-Javadoc)
*
* @see org.enilu.ibatis.dao.IStudentDAO#update(org.enilu.ibatis.vo.Student)
*/
public boolean update(Student stu) throws Exception {
if (sqlMapClient.update("updatestudent", stu) > 0) {
return true;
}
return false;
}
public List<Student> findAllByName(String name) throws Exception {
List all = null;
all = sqlMapClient.queryForList("listByName", name);
return all;
}
public void insertStudentBySequence(Student stu) throws Exception {
//从数据库中获取主键值,然后向数据库中插入学生
System.out.println(sqlMapClient.insert("insertStudentBySequence", stu));
System.out.println("sid:"+stu.getSid());
}
}
ibatis简单例子程序
4星 · 超过85%的资源 需积分: 9 54 浏览量
2008-11-12
09:26:17
上传
评论
收藏 3.27MB RAR 举报
eniluzt
- 粉丝: 32
- 资源: 14
最新资源
- app-release.apk.zip
- python-leetcode面试题解之第421题数组中两个数的最大异或值.zip
- python-leetcode面试题解之第416题分割等和子集.zip
- python-leetcode面试题解之第414题第三大的数.zip
- python-leetcode面试题解之第412题Fizz-Buzz.zip
- python-leetcode面试题解之第409题最长回文串.zip
- python-leetcode面试题解之第408题有效单词缩写.zip
- python-leetcode面试题解之第405题数字转换为十六进制数.zip
- python-leetcode面试题解之第404题左叶子之和.zip
- python-leetcode面试题解之第401题二进制手表.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈