ibatis增删改查技术

  • X7_918123
    了解作者
  • 15.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-20 05:12
    上传日期
ibatis 连接SQL2005数据库 增删改查操作
ibatis增删改查简单造作源码例子.zip
内容介绍
package com.itcast; import java.io.IOException; import java.io.Reader; import java.sql.Date; import java.sql.SQLException; import java.util.List; import com.ibatis.sqlmap.client.SqlMapClient; public class IStudentDAOImpl implements IStudentDAO { private static SqlMapClient sqlMapClient = null; static{ try { Reader reader=com.ibatis.common.resources.Resources.getResourceAsReader("com/itcast/SqlMapConfig.xml"); sqlMapClient =com.ibatis.sqlmap.client.SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void addStudent(Student student) { // TODO Auto-generated method stub try { sqlMapClient.insert("insertStudent", student); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void deleteStudentById(int id) { // TODO Auto-generated method stub try { sqlMapClient.delete("deleteStudentById", id); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public List<Student> queryAllStudent() { // TODO Auto-generated method stub List<Student> studentList=null; try { studentList=sqlMapClient.queryForList("selectAllStudent"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return studentList; } public Student queryStudent(int id) { Student student=null; try { student=(Student) sqlMapClient.queryForObject("selectStudentById", id); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return student; } public List<Student> queryStudentByName(String name) { // TODO Auto-generated method stub return null; } public void updateStudentById(Student student) { // TODO Auto-generated method stub try { System.out.println(sqlMapClient.update("updateStudentById", student)); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub IStudentDAO dao=new IStudentDAOImpl(); for(Student student:dao.queryAllStudent()){ System.out.println(student); } /*Student student=dao.queryStudent(2); System.out.println(student);*/ /*Student student=new Student(); student.setBirth(Date.valueOf("1994-11-09")); student.setMajor("土木工程"); student.setScore(88); student.setSid(5); student.setSname("Lily"); dao.addStudent(student);*/ //dao.deleteStudentById(5); /*Student student=new Student(); student.setBirth(Date.valueOf("1994-11-09")); student.setMajor("土木工程"); student.setScore(58); student.setSid(5); student.setSname("Lily"); dao.updateStudentById(student);*/ } }
评论
    相关推荐