hello,hellow

來源:互聯網
上載者:User

hello,hellow

學生管理資料庫系統:
建立步驟:
1)匯入jar包,建立資料庫,與資料庫連接。
2)將一些常用函數匯入到DbOperator類中,形成一個抽象工具包!靜態字執行一次,就是Class.forName(“”);接著就是活的串連;然後就是close方法,(ResultSet rs,Statement st,Connection conn)if(rs或者st或者conn不等於零)然後執行 rs.close(),或者st.close();或者conn.close();當然關閉的方法傳回值一定是void,(Statement st;Connection conn);直接執行close(null,st,conn); 3)建立物件導向的 增刪查修等用到的語句! <1>建立介面StudentManager public boolean add(Student stu); public boolean update(Student stu); public boolean del(int id); public Student getStudentById(int id); public List(Student) getStudents(); <2>建立StudentManagerImpl類 介面 於 StudentManager 借鑒與StudentManager的add,在try catch的最後記得添加finallyDbOperator.close(pst,conn);設定符號變數 flag。更新刪除操作類似,查詢無疑比較另類,比較麻煩! public List getStudents() { List list = new ArrayList(); Connection conn = null; Statement st = null; ResultSet rs = null; try { conn = DBOperator.getConnection(); String sql = “select * from student”; st = conn.createStatement(); rs = st.executeQuery(sql); while(rs.next()) { Student stu = new Student(); stu.setId(rs.getInt(“id”)); stu.setName(rs.getString(“name”)); stu.setNumber(rs.getString(“number”)); stu.setMath(rs.getInt(“math”)); stu.setEnglish(rs.getInt(“english”)); stu.setChinese(rs.getInt(“chinese”)); list.add(stu); } }catch(Exception ex) { ex.printStackTrace(); }finally { DBOperator.close(rs, st, conn); } return list; } 4)建立jsp檔案,設定前台登入頁面! jsp檔案用於存放一些靜態代碼,也可以用來添加一些動態代碼,與html是不同的! web.xml設定檔,是專門用來配置servlet檔案的! SQLYog 是MySQL 的圖形化頁面,最基礎的調用還是 通過dos視窗(黑框); 第一步:建立資料庫!建立相應的表單! 第二步:匯入jar包,jar包是驅動載入器,可以通過java代碼,獲得資料庫的串連方式! public static final String id;//字串 id是靜態常量 並且不可更改! Class.forName(DBDRIVER);將驅動的類載入到記憶體中去。 驅動載入器載入成功之後,寫一個方法得到資料庫的連線物件,->getConnection方法。 Connection conn=null;聲明一個連線物件! 第三步:驗證是否串連資料庫。所以要寫一個驗證串連的類! 做java程式的時候特別是web應用程式的時候要寫好包名,跟架構有關係。建立一個類,裡面一個main函數來測試資料庫連接是否成功!

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.