影音先锋男人资源在线观看,精品国产日韩亚洲一区91,中文字幕日韩国产,2018av男人天堂,青青伊人精品,久久久久久久综合日本亚洲,国产日韩欧美一区二区三区在线

javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解

上傳人:ren****ao 文檔編號(hào):143378707 上傳時(shí)間:2022-08-26 格式:DOC 頁(yè)數(shù):12 大?。?25KB
收藏 版權(quán)申訴 舉報(bào) 下載
javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解_第1頁(yè)
第1頁(yè) / 共12頁(yè)
javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解_第2頁(yè)
第2頁(yè) / 共12頁(yè)
javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解_第3頁(yè)
第3頁(yè) / 共12頁(yè)

下載文檔到電腦,查找使用更方便

9.9 積分

下載資源

還剩頁(yè)未讀,繼續(xù)閱讀

資源描述:

《javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解》由會(huì)員分享,可在線閱讀,更多相關(guān)《javaJDBC小項(xiàng)目《學(xué)生管理系統(tǒng)》源碼帶注解(12頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、Java+javabean+JDBC學(xué)生管理系統(tǒng) 一、 項(xiàng)目結(jié)構(gòu) 本項(xiàng)目是使用javabean和jdbc做的,這個(gè)包是實(shí)體包 這個(gè)是菜單包,源碼不會(huì)再發(fā)這些,自己寫(xiě)就好了。 二、 項(xiàng)目運(yùn)行結(jié)果 三、 源碼 廢話不多說(shuō),直接上源碼: 這兩個(gè)是關(guān)鍵源碼,是負(fù)責(zé)登錄和學(xué)生信息操作的邏輯類: public class AdminDaoImpl extends DBHelper implements AdminDao { Admin admin = null; /** * 登錄 */ @SuppressWarnings("resource"

2、) @Override public Admin login(String name) { String sql = "select * from admin where username=?"; Object[] param = {name}; Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; try { while (rs.next()) { admin = new Admin(); String username = rs.getSt

3、ring("username"); String password = rs.getString("password"); admin.setUsername(username); admin.setPassword(password); } } catch (SQLException e) { System.out.println("未找到此name"); } return admin; } } public class StudentDaoImpl extends DBHelper implements Stude

4、ntDao { Student stu = null; List list = null; @SuppressWarnings("resource") @Override public Student getInfoByid(int id) { String sql = "select * from student where id=?"; Object[] param = { id }; Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj

5、; stu = new Student(); try { while (rs.next()) { stu.setId(rs.getInt("id")); stu.setName(rs.getString("name")); stu.setAge(rs.getInt("age")); stu.setGender(rs.getString("gender")); stu.setGrade(rs.getString("grade")); stu.setPhone(rs.getLong("phone")); st

6、u.setEmail(rs.getString("email")); stu.setAddress(rs.getString("address")); } } catch (SQLException e) { e.printStackTrace(); } finally { this.closeAll(); } return stu; } @SuppressWarnings("resource") @Override public List getAllStu() { String sql =

7、 "select * from student"; Object obj = this.excute(sql, null); ResultSet rs = (ResultSet) obj; list = new ArrayList(); try { while (rs.next()) { stu = new Student(); stu.setId(rs.getInt("id")); stu.setName(rs.getString("name")); stu.setAge(rs.getInt("age"

8、)); stu.setGender(rs.getString("gender")); stu.setGrade(rs.getString("grade")); stu.setPhone(rs.getLong("phone")); stu.setEmail(rs.getString("email")); stu.setAddress(rs.getString("address")); list.add(stu); } } catch (SQLException e) { e.printStackTrace();

9、 } finally { this.closeAll(); } return list; } @SuppressWarnings("resource") @Override public String getNameById(int id) { String name = null; String sql = "select name from student where id=?"; Object[] param = { id }; Object obj = this.excute(sql, param); Result

10、Set rs = (ResultSet) obj; try { while (rs.next()) { name = rs.getString("name"); } } catch (SQLException e) { e.printStackTrace(); } finally { this.closeAll(); } return name; } @SuppressWarnings("resource") @Override public int getidByIntput(int id) {

11、 int num = 0; String sql = "select id from student where id=?"; Object[] param = { id }; Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; try { while (rs.next()) { num = rs.getInt("id"); } } catch (SQLException e) { e.printStackTrace(); } fi

12、nally { this.closeAll(); } return num; } @Override public boolean addStudent(Object[] param) { boolean b = false; String sql = "insert into student values(?,?,?,?,?,?,?,?)"; Object obj = this.excute(sql, param); b = (boolean) obj; return b; } @Override public

13、 boolean removeStuById(int id) { boolean b = false; String sql = "delete from student where id=?"; Object[] param = { id }; Object obj = this.excute(sql, param); b = (boolean) obj; return b; } @Override public boolean modifyAllStuById(Student stu) { boolean b = false;

14、 String sql = "update student set age = ?,grade=?,address=?,phone=?,email=? where id = ?"; Object[] param = { stu.getAge(), stu.getGrade(), stu.getAddress(), stu.getPhone(), stu.getEmail(), stu.getId() }; Object obj = this.excute(sql, param); b = (boolean) obj; return b; } @Ov

15、erride public boolean modifyPartStuById(Student stu, String attr) { boolean b = false; if (attr.equals("age")) { String sql = "update student set age =? where id=?"; Object[] param = { stu.getAge(), stu.getId() }; Object obj = this.excute(sql, param); b = (boolean) obj; }

16、else if (attr.equals("grade")) { String sql = "update student set grade =? where id=?"; Object[] param = { stu.getGrade(), stu.getId() }; Object obj = this.excute(sql, param); b = (boolean) obj; } else if (attr.equals("address")) { String sql = "update student set address =? w

17、here id=?"; Object[] param = { stu.getAddress(), stu.getId() }; Object obj = this.excute(sql, param); b = (boolean) obj; } else if (attr.equals("phone")) { String sql = "update student set phone =? where id=?"; Object[] param = { stu.getPhone(), stu.getId() }; Object obj =

18、 this.excute(sql, param); b = (boolean) obj; } else if (attr.equals("email")) { String sql = "update student set email =? where id=?"; Object[] param = { stu.getEmail(), stu.getId() }; Object obj = this.excute(sql, param); b = (boolean) obj; } return b; } } 好吧,到此

19、為止,邏輯算是完成了,接下來(lái)就是工具包,也就是JDBC通式 public class DBHelper { private static final String url = "jdbc:mysql://localhost:3306/sms?characterEncoding=utf-8"; private static final String Driver = "com.mysql.jdbc.Driver"; private static final String name = "root"; private static final String pwd = "sa

20、123456"; private Connection conn = null; private PreparedStatement pstmt = null; private ResultSet rs = null; /** * 創(chuàng)建數(shù)據(jù)庫(kù)連接 * * @return */ public Connection Getconn() { try { Class.forName(Driver); conn = DriverManager.getConnection(url, name, pwd); } catch (Cl

21、assNotFoundException e) { System.out.println("注冊(cè)驅(qū)動(dòng)失敗"); } catch (SQLException e) { System.out.println("驅(qū)動(dòng)包路徑錯(cuò)誤"); } return conn; } public Object excute(String sql, Object[] param) { int a = 0; Object o = null; this.Getconn(); try { pstmt = conn.prepareStatement

22、(sql); if (param != null) { for (int i = 0; i < param.length; i++) { pstmt.setObject(i + 1, param[i]); } } boolean b = pstmt.execute(); if (b) { rs = pstmt.getResultSet(); o = rs; } else { a = pstmt.getUpdateCount(); if (a > 0) { o = true

23、; } else { o = false; } closeAll(); } } catch (SQLException e) { e.printStackTrace(); } return o; } /** * 關(guān)閉數(shù)據(jù)庫(kù) */ public void closeAll() { try { if (rs != null) { rs.close(); } if (pstmt != null) { pstmt.close(); }

24、 if (conn != null) { conn.close(); } } catch (SQLException e) { System.out.println("錯(cuò)誤關(guān)閉"); } } } 至于這個(gè)類,是一些控制臺(tái)輸入信息判斷,當(dāng)然可以貼出來(lái)供大家參考~ /** * 匹配信息 * * @author Administrator * */ public class Matches { Scanner input = new Scanner(System.in); static String id =

25、null; static String gender = null; static String age = null; static String grade = null; static String phone = null; static String email = null; /** * 匹配id * * @return */ public String matchesId() { id = input.next(); if (Pattern.matches("^[0-9]{1,}$", id)) {

26、} else { System.out.println("輸入錯(cuò)誤,只能輸入數(shù)字:"); this.matchesId(); } return id; } /** * 匹配性別 * * @return */ public String matchesGender() { gender = input.next(); if (!(gender.equals("男") || gender.equals("女"))) { System.out.println("性別只能是男或者女:"); this.ma

27、tchesGender(); } return gender; } /** * 匹配年齡 * * @return */ public int matchesAge() { age = input.next(); if (!Pattern.matches("^[0-9]{1,}$", age)) { System.out.println("以上輸入不合法,只能輸入1-120之內(nèi)的數(shù)字:"); this.matchesAge(); } else if (Integer.valueOf(age) < 1 || I

28、nteger.valueOf(age) > 120) { System.out.println("以上輸入不合法,只能輸入1-120之內(nèi)的數(shù)字:"); this.matchesAge(); } return Integer.parseInt(age); } /** * 匹配年級(jí) * * @return */ public String matchesGrade() { grade = input.next(); if (!(grade.equals("初級(jí)") || grade.equals("中級(jí)") || g

29、rade.equals("高級(jí)"))) { System.out.println("無(wú)此年級(jí)設(shè)置,年級(jí)只能輸入初級(jí)、中級(jí)或高級(jí),請(qǐng)重新輸入:"); this.matchesGrade(); } return grade; } /** * 匹配手機(jī)號(hào) * * @return */ public long matchesPhone() { phone = input.next(); if (!Pattern.matches("^[0-9]{11}$", phone)) { System.out.println

30、("輸入有誤,電話號(hào)碼只能是11位數(shù)字,請(qǐng)重新輸入:"); this.matchesPhone(); } return Long.parseLong(phone); } /** * 匹配email * * @return */ public String matchesEmail() { email = input.next(); if (!Pattern.matches("^[0-9a-zA-Z]+@[0-9a-zA-Z]+.[0-9a-zA-Z]+$", email)) { System.out.println("郵箱格式有誤,請(qǐng)輸入正確的電子郵箱(包含@和.com)"); this.matchesEmail(); } return email; } } 好了,別的我就不說(shuō)了,怎么調(diào)用,我更就不用說(shuō)了吧? 本文為原創(chuàng)作品,轉(zhuǎn)載需注明出處

展開(kāi)閱讀全文
溫馨提示:
1: 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔
關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!