




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
sqljdbc.jarJavajrelib\ext目錄下,在我的機器是因為我使用的是MyEclipse6.5開發(fā)工具. 要在代碼中刪除package這行語句packagejavacd參數(shù)-d不可以少packageimportpublicclass{privateStringDBDRIVER privateStringDBURL privateString privateString privateConnection =nullpublic{{
}catch(Exception{}}publicConnection{returnthis.conn}publicvoid{{}
catch(Exception{}}測試連接是否可以用的smis.sm.DBTest.JAVA packagesmis.sm;importsmis.db.dbc.*;publicclassDBTest{*@parampublicstaticvoidmain(String[]args)//TODOAuto-generatedmethodstubDataBaseConnectiondbc=null;dbc=new}{}{System.out.println("CannotgetA}}packagesmis.sm.vo;importjava.sql.*;publicclassStudent{privateStringno;privateStringname;privateStringsex;privateDatebirthday;privateStringdepartment;privateStringtelephone;publicStringgetNo(){return}publicvoidsetNo(Stringno)this.no=}publicStringgetName()return}publicvoidsetName(Stringname)=}publicStringgetSex()return}publicvoidsetSex(Stringsex)this.sex=}publicDategetBirthday()return}publicvoidsetBirthday(Datebirthday)this.birthday=}publicStringgetDepartment()return}publicvoidsetDepartment(Stringdepartment)this.department=}publicStringgetTelephone()return}publicvoidsetTelephone(Stringtelephone)this.telephone=}}packagesmis.sm.dao;importsmis.sm.vo.*;importjava.util.*;publicinterfaceStudentDAOpublicvoidinsert(Studentstudent)throwsExceptionpublicvoidupdate(Studentstudent)throwsExceptionpublicvoiddelete(Stringno)throwsExceptionpublicStudentqueryByNo(Stringno)throwsExceptionpublicListqueryAll()throwsExceptionpublicListqueryByLike(Stringcond)throwsException}packageimportimportjava.util.ArrayList;importjava.util.List;importsmis.db.dbc.*;importimportpublicclassStudentDAOImplimplementsStudentDAOpublicvoiddelete(Stringno)throwsException//Stringsql"DELETEFromSWHERE學號PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ pstmt.setString(1,no);pstmt.executeUpdate();pstmt.close();}catch(Exception{}{dbc.close()}}//publicvoidinsert(Studentstudent)throwsException//TODOAuto-generatedmethodStringsql"INSERTINTOS(學號,姓名,性別,出生日期,系PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ dbc.getConnection().prepareStatement(sql);pstmt.setString(1,student.getNo());pstmt.setString(2,student.getName());pstmt.setString(3,student.getSex());pstmt.setDate(4,student.getBirthday());pstmt.setString(6,student.getTelephone());pstmt.executeUpdate();pstmt.close()}catch(Exception{//System.out.println(e)}{dbc.close()}}//publicListqueryAll()throwsExceptionS"
//TODOAuto-generatedmethodstubListall=newArrayList();PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ dbc.getConnection().prepareStatement(sql);ResultSetrs=pstmt.executeQuery();{Studentstudent=newStudent();all.add(student)}rs.close();pstmt.close();}catch(Exception{}{dbc.close()}returnall}//publicListqueryByLike(Stringcond)throwsException//TODOAuto-generatedmethodstubListall=newArrayList();SWHERE學號LIKE?or姓名LIKE?or系LIKE?orLIKE?"PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ dbc.getConnection().prepareStatement(sql);pstmt.setString(1,"%"+cond+"%");pstmt.setString(2,"%"+cond+"%");pstmt.setString(3,"%"+cond+"%");pstmt.setString(4,"%"+cond+"%");ResultSetrs=pstmt.executeQuery();{Studentstudent=newStudent();all.add(student)}rs.close();pstmt.close();}catch(Exception{}{dbc.close()}returnall}//nopublicStudentqueryByNo(Stringno)throwsException//TODOAuto-generatedmethodstubStudentstudent=null;SWHERE學號PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ pstmt.setString(1,no);ResultSetrs=pstmt.executeQuery(){}rs.close();pstmt.close();}catch(Exception{}{dbc.close()}returnstudent}//publicvoidupdate(Studentstudent)throwsException//TODOAuto-generatedmethodStringsql"UPDATESSET姓名=?,性別=?,出生日期=?,PreparedStatementpstmt=null;DataBaseConnectiondbc=null;dbc=newDataBaseConnection();{ dbc.getConnection().prepareStatement(sql);pstmt.setString(1,student.getName());pstmt.setString(2,student.getSex());pstmt.setDate(3,student.getBirthday());pstmt.setString(5,student.getTelephone());pstmt.setString(6,student.getNo());pstmt.executeUpdate();pstmt.close()}catch(Exception{}{dbc.close()}}}packagesmis.sm.factory;importsmis.sm.dao.*;publicclassDAOFactory{publicstaticStudentDAO{returnnewStudentDAOImpl()}} packageimportsmis.sm.factory.*;importsmis.sm.vo.*;importjava.sql.*;importimportimportpublicclassStudentTestpublicstaticvoidmain(String[]args)//TODOAuto-generatedmethod}publicstaticvoid{Listall=null;);Studentfor(int{student=(Student)all.get(i);}}publicstaticvoid{Studentstudent=newStudent();student.setBirthdayjava.sql.Date.valueOf("2010-5-20"));}catch(Ex
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)無息借款協(xié)議書
- 遺留房產(chǎn)分割協(xié)議書
- 煤礦采煤師徒協(xié)議書
- 軟體工廠轉(zhuǎn)讓協(xié)議書
- 醫(yī)院員工培訓協(xié)議書
- 垃圾分類服務協(xié)議書
- 區(qū)域經(jīng)銷代理協(xié)議書
- 貨款結(jié)算協(xié)議書參考
- 妻子轉(zhuǎn)讓協(xié)議書范文
- 養(yǎng)殖安全協(xié)議書模板
- 2025 年深入貫徹中央八項規(guī)定精神學習教育實施方案
- 《Python程序設計》全套教學課件
- 2025年空壓機行業(yè)發(fā)展戰(zhàn)略研究及投資潛力預測評估報告
- 2025年河北省石家莊市一中、唐山一中等“五個一”名校高三全真模擬(最后一卷)生物試題試卷含解析
- 院科兩級人員緊急替代程序與替代方案
- 《金屬加工基礎(第二版)》中職全套教學課件
- 2025年湖北省初中學業(yè)水平考試數(shù)學模擬卷(二)(原卷版+解析版)
- 2025年華能新能源股份有限公司廣東分公司應屆高校畢業(yè)生招聘筆試參考題庫附帶答案詳解
- 2025年新疆克州中考英語一模試卷
- 2024年新疆伊犁州直檢察機關(guān)招聘聘用制書記員筆試真題
- 口腔四手操作培訓
評論
0/150
提交評論