java增刪改查,包括存儲過程插入_第1頁
java增刪改查,包括存儲過程插入_第2頁
java增刪改查,包括存儲過程插入_第3頁
java增刪改查,包括存儲過程插入_第4頁
java增刪改查,包括存儲過程插入_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論