




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1. publicclassNoteDAOImplimplementsNoteDAO 2. /增加操作 3. publicvoidinsert(Notenote)throwsException 4. Stringsql=INSERTINTOnote(id,title,author,content)VALUES(note_sequ.nextVal,?,?,?); 5. PreparedStatementpstmt=null; 6. DataBaseConnectiondbc=null; 7. dbc=newDataBaseConnection(); 8. try 9. pstmt=dbc.getConnection().prepareStatement(sql); 10. pstmt.setString(1,note.getTitle(); 11. pstmt.setString(2,note.getAuthor(); 12. pstmt.setString(3,note.getContent(); 13. pstmt.executeUpdate(); 14. pstmt.close(); 15. catch(Exceptione) 16. /System.out.println(e); 17. thrownewException(操作中出现错误!); 18. finally 19. dbc.close(); 20. 21. 22. /修改操作 23. publicvoidupdate(Notenote)throwsException 24. Stringsql=UPDATEnoteSETtitle=?,author=?,content=?WHEREid=?; 25. PreparedStatementpstmt=null; 26. DataBaseConnectiondbc=null; 27. dbc=newDataBaseConnection(); 28. try 29. pstmt=dbc.getConnection().prepareStatement(sql); 30. pstmt.setString(1,note.getTitle(); 31. pstmt.setString(2,note.getAuthor(); 32. pstmt.setString(3,note.getContent(); 33. pstmt.setInt(4,note.getId(); 34. pstmt.executeUpdate(); 35. pstmt.close(); 36. catch(Exceptione) 37. thrownewException(操作中出现错误!); 38. finally 39. dbc.close(); 40. 41. 42. /删除操作 43. publicvoiddelete(intid)throwsException 44. Stringsql=DELETEFROMnoteWHEREid=?; 45. PreparedStatementpstmt=null; 46. DataBaseConnectiondbc=null; 47. dbc=newDataBaseConnection(); 48. try 49. pstmt=dbc.getConnection().prepareStatement(sql); 50. pstmt.setInt(1,id); 51. pstmt.executeUpdate(); 52. pstmt.close(); 53. catch(Exceptione) 54. thrownewException(操作中出现错误!); 55. finally 56. dbc.close(); 57. 58. 59. /按ID查询,主要为更新使用 60. publicNotequeryById(intid)throwsException 61. Notenote=null; 62. Stringsql=SELECTid,title,author,contentFROMnoteWHEREid=?; 63. PreparedStatementpstmt=null; 64. DataBaseConnectiondbc=null; 65. dbc=newDataBaseConnection(); 66. try 67. pstmt=dbc.getConnection().prepareStatement(sql); 68. pstmt.setInt(1,id); 69. ResultSetrs=pstmt.executeQuery(); 70. if(rs.next() 71. note=newNote(); 72. note.setId(rs.getInt(1); 73. note.setTitle(rs.getString(2); 74. note.setAuthor(rs.getString(3); 75. note.setContent(rs.getString(4); 76. 77. rs.close(); 78. pstmt.close(); 79. catch(Exceptione) 80. thrownewException(操作中出现错误!); 81. finally 82. dbc.close(); 83. 84. returnnote; 85. 86. /查询全部 87. publicListqueryAll()throwsException 88. Listall=newArrayList(); 89. Stringsql=SELECTid,title,author,contentFROMnote; 90. PreparedStatementpstmt=null; 91. DataBaseConnectiondbc=null; 92. dbc=newDataBaseConnection(); 93. try 94. pstmt=dbc.getConnection().prepareStatement(sql); 95. ResultSetrs=pstmt.executeQuery(); 96. while(rs.next() 97. Notenote=newNote(); 98. note.setId(rs.getInt(1); 99. note.setTitle(rs.getString(2); 100. note.setAuthor(rs.getString(3); 101. note.setContent(rs.getString(4); 102. all.add(note); 103. 104. rs.close(); 105. pstmt.close(); 106. catch(Exceptione) 107. System.out.println(e); 108. thrownewException(操作中出现错误!); 109. finally 110. dbc.close(); 111. 112. returnall; 113. 114. /模糊查询 115. publicListqueryByLike(Stringcond)throwsException 116. Listall=newArrayList(); 117. Stringsql=SELECTid,title,author,contentFROMnoteWHEREtitleLIKE?orAUTHORLIKE?orCONTENTLIKE?; 118. PreparedStatementpstmt=null; 119. DataBaseConnectiondbc=null; 120. dbc=newDataBaseConnection(); 121. try 122. pstmt=dbc.getConnection().prepareStatement(sql); 123. pstmt.setString(1,%+cond+%); 124. pstmt.setString(2,%+cond+%); 125. pstmt.setString(3,%+cond+%); 126. ResultSetrs=pstmt.executeQuery(); 127. while(rs.next() 128. Notenote=newNote(); 129. note.setId(rs.getInt(1); 130. note.setTitle(rs.getString(2); 131. note.setAuthor(rs.getString(3); 132. note.setContent(rs.getString(4); 133. all.add(note); 134. 135. rs.close(); 136. pstmt.close(); 137
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- IDO5L-Standard-生命科学试剂-MCE
- HO-PEG-AS-MW-1000-生命科学试剂-MCE
- 2025年甘肃省平凉市崆峒区殡仪馆招聘合同制工作人员模拟试卷及答案详解(夺冠)
- 2025年甘肃省甘南州临潭县卫生健康系统引进紧缺卫生专业技术人才20人模拟试卷完整参考答案详解
- 2025福建海峡人力资源股份有限公司平潭分公司(第一批)招聘延长模拟试卷及完整答案详解一套
- 2025北京中国音乐学院高层次人才引进2人模拟试卷及参考答案详解1套
- 安全培训效果自评课件
- 《二维空间坐标系应用:高三数学教学教案》
- 农产品质量监测方案设计
- 2025年上半年四川泸州市妇幼保健院面向社会招聘编外人员19名考前自测高频考点模拟试题及一套答案详解
- 爆炸物品生产安全操作规程
- 中华人民共和国统计法
- 热电厂输煤作业安全培训
- 形成性评价指导性规范:SOAP病例汇报评价
- 燃料电池+基础理论动力学+热力学+研究方法
- 高等数学教材(文科)
- 歌词:半生雪(学生版)
- 九江学院学位英语往年考题
- 药品不良反应培训试题
- 2024-2030年中国纳米晶软磁材料行业市场发展趋势与前景展望战略分析报告
- 五级保健按摩师(初级)职业技能鉴定考试题库-下(判断题)
评论
0/150
提交评论