




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、importimportimportimportimportimportimportimportimportclass Student implements Serializable private static final long serialVersionUIDint no;String name;String sex;int age;public Student( super(;public Student(int no, String name, String sex, int age super(;this.no = no; = name;this.sex = s
2、ex;this.age = age;public int getNo( return no;public void setNo(int no this.no = no;public String getName( return name;public void setName(String name = name;public String getSex( return sex;public void setSex(String sex this.sex = sex;public int getAge( return age;public void setAge(int a
3、ge this.age = age;public static long getSerialVersionUID( return serialVersionUID;interface StudentDao public int insert(Student stu;public void insert_proc(Student stu; /调用存储过程public ArrayList queryAll(; abstract class StudentDaoImpl implements StudentDao public int insert1(Student stuConnection co
4、nn=DBUtil.getNewConnection(;PreparedStatement pstmt=null;int count=-1;try pstmt=conn.prepareStatement(insert into Student valeus(?,?,?,?;pstmt.setInt(1, stu.getNo(;pstmt.setString(2, stu.getName(;pstmt.setString(3, stu.getSex(;pstmt.setInt(4, stu.getAge(;count=pstmt.executeUpdate(; catch (SQLExcepti
5、on e e.printStackTrace(; finallyDBUtil.close(pstmt;DBUtil.close(conn;return count;public void insert_proc(Student stu Connection conn=DBUtil.getNewConnection(;CallableStatement call=null;try call=conn.prepareCall(call proc_insert(?,?,?,?;call.setInt(1, stu.getNo(;call.setString(2, stu.getName(;call.
6、setString(3, stu.getSex(;call.setInt(4, stu.getAge(;call.executeUpdate(; catch (SQLException e e.printStackTrace(;finallyDBUtil.close(call;DBUtil.close(conn;public ArrayList queryAll( Connection conn=DBUtil.getNewConnection(;PreparedStatement pstmt=null;ResultSet rs=null;ArrayList stus= new ArrayLis
7、t (; try pstmt=conn.prepareStatement(select * from student where 1=1;rs=pstmt.executeQuery(;Student stu=null;while(rs!=null&rs.next(stu=new Student(;stu.setNo(rs.getInt(sno;stu.setName(rs.getString(sname;stu.setSex(rs.getString(sex;stu.setAge(rs.getInt(age;stus.add(stu; catch (SQLException e e.print
8、StackTrace(;finallyDBUtil.close(rs;DBUtil.close(pstmt;DBUtil.close(conn;return null;public int insert(Student stu / TODO Auto-generated method stubreturn 0;class DBUtil public static Connection getNewConnection(Connection conn=null;try Class.forName(;conn=DriverManager.getConnection(jdbc:sqlserver:/
9、localhost:1433;databaseName=StudentDB, sa, sasa; catch (ClassNotFoundException e e.printStackTrace(; catch (SQLException e e.printStackTrace(;return conn;public static void close(PreparedStatement pstmtif(pstmt!=nulltry pstmt.close(; catch (SQLException e e.printStackTrace(;public static void close(
10、ResultSet rsif(rs!=nulltry rs.close(; catch (SQLException e e.printStackTrace(;public static void close(Connection connif(conn!=nulltry conn.close(; catch (SQLException e e.printStackTrace(;public void close(Statement stmtif(stmt!=nulltry stmt.close(; catch (SQLException e e.printStackTrace(;public
11、class TestStudentDaoImpl static StudentDao sdi= new StudentDaoImpl(;public static void main(String args public static void insert(Student stu=new Student(;stu.setNo(5;stu.setName(刘巴;stu.setSex(女;stu.setAge(18;sdi.insert(stu;public static void queryAll(ArrayList stus= sdi.queryAll(;if(stus!=nullfor(Student
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年食安考试题库及答案中级
- 2025年汽车营销师中级试题及答案
- 2025年化验人员试题及答案
- 2025年电工产品测试题及答案大全
- 2025年java oracle 面试题及答案
- 机车租车协议书
- 村屯绿化协议书
- 2025年焊工考试题及答案
- 村级维护协议书
- 2025年护理中职专业课笔试题及答案
- 长期陪伴协议书范本
- 邵雍《渔樵问对》(原文+译文+解读)
- 景区安全生产管理规章制度大全
- 矿山雨季生产安全知识培训
- 食源性疾病培训内容知识
- 投标绩效激励管理办法
- 输血相关法律法规知识培训
- CNAS-CC190-2021 能源管理体系认证机构要求
- 2025年上半年中国南水北调集团新能源投资限公司抽水蓄能项目岗位公开招聘易考易错模拟试题(共500题)试卷后附参考答案
- 在职业教育产教融合对话会上的讲话
- 消毒隔离知识培训内容
评论
0/150
提交评论