版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
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; /調(diào)用存儲過程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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 揚(yáng)塵治理委托協(xié)議模板
- 2025年度文化創(chuàng)意產(chǎn)品開發(fā)合作協(xié)議范本3篇
- 2025版外債借款合同法律框架與政策背景分析3篇
- 2025年銷售薪資與銷售團(tuán)隊建設(shè)合同2篇
- 2025版押一付三車位租賃合同模板參考9篇
- 2025年高端住宅產(chǎn)權(quán)轉(zhuǎn)讓合同范本3篇
- 2025-2030全球熔鹽儲熱設(shè)備行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國實(shí)驗室渦旋混合器行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025版投票權(quán)委托合同:股東權(quán)益保護(hù)專項3篇
- 2025年度綠色有機(jī)農(nóng)產(chǎn)品個人果園承包經(jīng)營合同書4篇
- 2025年N1叉車司機(jī)考試試題(附答案)
- 《醫(yī)院財務(wù)分析報告》課件
- 2025老年公寓合同管理制度
- 2024年考研政治試題及答案
- 2024-2025學(xué)年人教版數(shù)學(xué)六年級上冊 期末綜合卷(含答案)
- 2024中國汽車后市場年度發(fā)展報告
- 感染性腹瀉的護(hù)理查房
- 天津市部分區(qū)2023-2024學(xué)年高二上學(xué)期期末考試 物理 含解析
- 《人工智能基礎(chǔ)》全套英語教學(xué)課件(共7章)
- GB/T 35613-2024綠色產(chǎn)品評價紙和紙制品
- 2022-2023學(xué)年五年級數(shù)學(xué)春季開學(xué)摸底考(四)蘇教版
評論
0/150
提交評論