- 5
- 0
- 约3.64千字
- 约 4页
- 2018-03-31 发布于河南
- 举报
dao层增删改查
/** * */packagecom.ys.dao.impl;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.ArrayList;importjava.util.List;importcom.ys.bean.Person;importcom.ys.dao.PersonDao;/** * @author Administrator * */publicclassPersonDaoImplimplementsPersonDao {privatestatic Connection connection;static {try {connection = DBUtils.getConn();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}/* (non-Javadoc) * @see com.ys.dao.impl.PersonDao#addPerson(com.ys.model.Person) */publicbooleanaddPerson(Person person) {boolean result = false;try {String sql = insert into person(id,name) values (?,?);PreparedStatementps = connection.prepareStatement(sql);ps.setInt(1, person.getId());ps.setString(2, person.getName());ps.execute();result = true;System.out.println(result = + result);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();result = false;} /*finally {try {connection.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}*/return result;}/* (non-Javadoc) * @see com.ys.dao.impl.PersonDao#delPerson(int) */publicbooleandelPerson(intidValue) {boolean result = false;try {String sql = delete from person where id = + idValue;PreparedStatementps = connection.prepareStatement(sql);ps.execute();int count = ps.getUpdateCount(); if(count != -1) {result = true;} else {result = false;}System.out.println(result = + result);} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();result = false;} /*finally {try {connection.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}*/return result;}/* (non-Javadoc) * @see com.ys.dao.impl.PersonDao#getById(int) */public Person getById(intidValue) {// TODO Auto-generated method stubString sql = select * from person where id = + idValue;Statement st;Person person = newPerson();try {st = connection.createStatemen
您可能关注的文档
最近下载
- 2026秋招:贵州黔晟国有资产经营公司笔试题及答案.doc VIP
- 年产5万吨氢氧化镁、5万吨碱式碳酸镁、1万吨氧化锆、1000吨硼酸锌、1000吨五硼酸铵和100吨钛酸钡产品项目环境影响报告书.pdf VIP
- 泵站安全培训课件.ppt VIP
- 工程成本会计会计要素03会计要素7利润.pdf VIP
- 《电气工程复习题》课件.ppt
- 贵州国企招聘:2025贵州省黔晟国有资产经营有限责任公司选聘考前自测高频考点模拟试题及答案详解1套.docx VIP
- 高一中外历史纲要(上)的知识点总结 .pdf VIP
- 【通用版】高考地理常考必背15种主观题题型答题模板梳理汇编(含高考模拟试卷及答案3套).docx VIP
- 25秋 典中点 三年级数学上(R版)极速提分法.docx VIP
- 体检主要检查项目临床意义及正常值详解-体检主要检查项目临.docx VIP
原创力文档

文档评论(0)