?? ?? 本期帶領大家一起來學習java課程設計(學生信息管理系統(tǒng)設計)+數(shù)據(jù)庫的實現(xiàn)思路 ?? ??
題目要求+數(shù)據(jù)庫??
學生信息包括:學號,姓名,年齡,性別,出生年月,地址,電話,E-mail等。試設計學生信息管理系統(tǒng),使之能提供以下功能:
1、系統(tǒng)以菜單方式工作
2、學生信息錄入功能--輸入
3、學生信息瀏覽功能--輸出
4、學生信息查詢功能--算法
按學號查詢
按姓名查詢
5、學生信息的刪除與修改(可選項)
一 、環(huán)境搭建??
在idea創(chuàng)建一個工程文件,在工程文件下創(chuàng)建一個model模塊,在model模塊下創(chuàng)建一個classSystem包,然后再存放對應的類,如下圖所示
需要注意是因為連接了數(shù)據(jù)庫,所以需要導入相應的jar包
二 、功能實現(xiàn) ?? ??
1.學生信息類的創(chuàng)建?
首先實現(xiàn)這個學生信息管理系統(tǒng),我們需要先創(chuàng)建一個學生信息類
,包括學生的學號,姓名,年齡,地址,電話,郵箱,出生日期,具體代碼如下?? ?? ??
package classSystem;
public class Student {
private int stuId;
private String name;
private int age;
private String sex;
private String birth;
private String address;
private String tel;
private String Email;
public Student() {
}
public Student(int stuId, String name, int age, String sex, String birth, String address, String tel, String email) {
this.stuId = stuId;
this.name = name;
this.age = age;
this.sex = sex;
this.birth = birth;
this.address = address;
this.tel = tel;
Email = email;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
Email = email;
}
}
2.學生信息的添加功能??
?? ??因為這個學生信息管理系統(tǒng)的java程序是連接了數(shù)據(jù)庫,所以我們在錄入我們的信息的時候,需要講我們所錄入的學生信息存放到數(shù)據(jù)庫當中,所以我們需要運用到sql語句
去添加我們所錄入的信息,做到了隨時隨地可以查詢,更好地管理我們的學生信息?? ??
public static void addStu(ArrayList<Student> stu) throws AWTException {
while (true) {
Extents.clearConsole();
System.out.println(">首界面>功能界面>添加學生信息\n\n");
Scanner sc = new Scanner(System.in);
System.out.print("請輸入學生學號(例:2022): ");
int stuId=sc.nextInt();
System.out.print("請輸入學生姓名(例:張三): ");
String name = sc.next();
System.out.print("請輸入學生年齡(例:18): ");
int age = sc.nextInt();
System.out.print("請輸入學生性別(例:男): ");
String sex =sc.next();
System.out.print("請輸入學生出生日期(例:2004-6-1): ");
String birth =sc.next();
System.out.print("請輸入學生電話(例:123456): ");
String tel=sc.next();
System.out.print("請輸入學生email(例:123456@qq.com): ");
String emial =sc.next();
System.out.print("請輸入學生地址(例:深圳): ");
String address = sc.next();
System.out.println("\n\n-----------------------------------------------------");
System.out.println( "\t\t學號: "+stuId+"\t\t姓名: " + name + "\t\t年齡: " + age + "\t\t地址: " + address
+"\t\t性別: " +sex+"\t\t出生日期: " +birth+"\t\t地址: " +address+"\t\t電話: " +tel+"\t\t郵箱: " +emial);
System.out.print("\n\n是否添加該學生信息? [Yes(1) / No(0)] :");
Extents.isAdd(stu, sc, stuId,sex,birth,tel,emial, name, age, address);
System.out.println("\n\n\n>首界面>功能界面>添加學生信息\n");
System.out.println("\t 繼續(xù)添加 請輸入1 ");
System.out.println();
System.out.println("\t 返回上級 請輸入0 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.print("\n請輸入您的選擇:");
while (true) {
int choose = sc.nextInt();
if (choose == 1) {
break;
} else if (choose == 0) {
Extents.clearConsole();
return;
} else {
System.out.print("看清選項! 再給你一次機會: ");
}
}
}
}
public static void isAdd(ArrayList<Student> stu, Scanner sc,int stuId ,String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
while (true) {
int is = sc.nextInt();
if (is == 0) {
Extents.clearConsole();
System.out.println("取消成功!");
break;
} else if (is == 1) {
/*Student s = new Student(stuId,name, age,sex,birth, address,tel,email);
stu.add(s);*/
Connection connection =null;
String sql ="insert into Student values(?,?,?,?,?,?,?,?)";
PreparedStatement preparedStatement=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,stuId);
preparedStatement.setString(2,name);
preparedStatement.setInt(3,age);
preparedStatement.setString(4,sex);
preparedStatement.setString(5,address);
preparedStatement.setString(6,birth);
preparedStatement.setString(7,tel);
preparedStatement.setString(8,email);
//執(zhí)行
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(null,preparedStatement,connection);
}
stuId += 1;
Extents.clearConsole();
System.out.println("添加信息成功!\n\n");
FunctionalBlock.showStu(stu);
break;
}
System.out.print("\n輸入錯誤!請重新輸入:");
}
}
相信大家看到這里會有點迷惑,那么現(xiàn)在我來梳理一下增加信息代碼塊的實現(xiàn)邏輯
首先我們先在FunctionalBlock當中的addStudan當中錄入我們的信息?? ??
然后再調用我們Extens當中的isAdd判斷是否錄入我們的信息
如果錄入信息的話,使用sql語句進行與數(shù)據(jù)庫的連接,并且將信息錄入到數(shù)據(jù)庫當中
并且會查詢數(shù)據(jù)庫當中的信息?? ??
如果不錄入信息的話,那么就取消錄入
增加學生信息效果圖如下
3.學生信息的刪除功能???
學生信息的刪除功能的實現(xiàn),先調用FunctionalBlock
當中的showStu的方法展示全部學生的信息????
再選擇需要刪除的學生信息????
同樣先要判斷所輸入的學號是=是否存在,用到了Extents當中的getFlag的方法
如果不存在,則返回-1,存在的話則進行刪除操作
同樣用到了sql語句與數(shù)據(jù)庫當中的學生信息進行了交互??
public static void deleteStu(ArrayList<Student> stu) throws AWTException {
Scanner sc = new Scanner(System.in);
showStu(stu);
while (true) {
System.out.print("\n請輸入要刪除的學生學號:");
int sid = sc.nextInt();
sc.nextLine();
int flag = Extents.getFlag(stu, sid);
if (flag == -1) {
System.out.print("\n該學號不存在,請重新輸入\n");
} else {
System.out.print("\n是否刪除學號為:" + sid + " 的學生信息? [Yes(1) / No(0)] :");
Extents.isDlete(stu, sc, flag);
System.out.println("\n\n\n>首界面>功能界面>刪除學生信息\n");
System.out.println("\t 繼續(xù)刪除 請輸入1 ");
System.out.println();
System.out.println("\t 返回上級 請輸入0 ");
System.out.println("\t ----------------------------------------------------------------");
System.out.print("\n請輸入您的選擇: ");
while (true) {
int choose = sc.nextInt();
if (choose == 1) {
break;
} else if (choose == 0) {
Extents.clearConsole();
return;
} else {
System.out.print("看清選項! 再給你一次機會: ");
}
}
}
}
}
刪除學生信息效果圖如下
4.學生信息的修改功能 ????
修改學生信息的功能呢,和上面刪除學生信息 功能的實現(xiàn)類似,我們同樣來看看如何實現(xiàn)的
學生信息的修改功能的實現(xiàn),先調用FunctionalBlock當中的showStu的方法展示全部學生的信息
再選擇需要修改的學生學號?? ??? ?
同樣先要判斷所輸入的學號是=是否存在,用到了Extents當中的getFlag的方法
如果不存在,則返回-1,存在的話則進行修改操作
再然后輸入修改之后的學生信息????
同樣用到了sql語句與數(shù)據(jù)庫當中的學生信息進行了交互
public static void updateStu(ArrayList<Student> stu) throws AWTException {
Scanner sc = new Scanner(System.in);
while (true) {
showStu(stu);
System.out.print("\n\n請輸入要修改信息的學生學號:");
int sidUpdate = sc.nextInt();
int flag = Extents.getFlag(stu, sidUpdate);
Extents.clearConsole();
if (flag == -1) {
System.out.print("該學號不存在,請重新輸入\n\n\n ");
} else {
System.out.println(">首界面>功能界面>修改學生信息\n\n");
System.out.print("請輸入學生學號(例:2022: ");
int id=sc.nextInt();
System.out.print("請輸入學生姓名(例:張三): ");
String name = sc.next();
System.out.print("請輸入學生年齡(例:18): ");
int age = sc.nextInt();
System.out.print("請輸入學生性別(例:男): ");
String sex =sc.next();
System.out.print("請輸入學生出生日期(例:2004-6-1): ");
String birth =sc.next();
System.out.print("請輸入學生電話(例:123456): ");
String tel=sc.next();
System.out.print("請輸入學生email(例:123456@qq.com): ");
String emial =sc.next();
System.out.print("請輸入學生地址(例:深圳): ");
String address = sc.next();
Extents.clearConsole();
Extents.getFlag(stu, sidUpdate);
Connection connection =null;
String sql ="update Student set stuId=? ,name=?,age=?,sex=?,adress=?,birth=?,tel=?,Email=?where stuId=?";
PreparedStatement preparedStatement=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,id);
preparedStatement.setString(2,name);
preparedStatement.setInt(3,age);
preparedStatement.setString(4,sex);
preparedStatement.setString(5,address);
preparedStatement.setString(6,birth);
preparedStatement.setString(7,tel);
preparedStatement.setString(8,emial);
preparedStatement.setInt(9,flag);
//執(zhí)行
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(null,preparedStatement,connection);
}
System.out.println(">首界面>功能界面>修改學生信息");
System.out.println("\n\n------------------------------------------------------------------");
System.out.println("修改后——>\n");
System.out.println( "\t\t姓名: " + name + "\t\t年齡: " + age + "\t\t地址: " + address
+"\t\t性別: " +sex+"\t\t出生日期: " +birth+"\t\t地址: " +address+"\t\t電話: " +tel+"\t\t郵箱: " +emial);
System.out.print("\n\n是否修改該學生信息? [Yes(1) / No(0)] :");
Extents.isUpdata(stu, sc, sidUpdate, flag,sex,birth,tel,emial, name, age, address);
System.out.println("\n\n\n>首界面>功能界面>修改學生信息\n");
System.out.println("\t 繼續(xù)修改 請輸入1 ");
System.out.println();
System.out.println("\t 返回上級 請輸入0 ");
System.out.println("\t --------------------------------------------------------------");
System.out.print("\n請輸入您的選擇:");
while (true) {
int choose = sc.nextInt();
if (choose == 1) {
Extents.clearConsole();
break;
} else if (choose == 0) {
Extents.clearConsole();
return;
} else {
System.out.print("看清選項! 再給你一次機會: ");
}
}
}
}
}
修改學生信息效果圖如下
5.學生信息的查看功能?????
由于查看學生信息的功能在前面三個功能當中都有調用?? ??? ?
所以我們?yōu)榱耸沟么a更加簡潔,將查詢學生信息的功能封裝起來了
避免了代碼的冗余
同樣我們來看看到底是如何實現(xiàn)的
因為我們的程序是連接了數(shù)據(jù)庫,所以我們需要查詢學生的信息的時候?? ??? ?
需要用到查詢的sql語句進行查詢,同我們的數(shù)據(jù)庫進行交互
public static void showStu(ArrayList<Student> stu) {
System.out.println("1.按學號查詢");
System.out.println("2.按姓名查詢");
System.out.println("3.查詢全部 ");
Scanner sc =new Scanner(System.in);
int input=sc.nextInt();
if(input==1){
System.out.print("輸入需要查詢的學生學號:");
int stuid=sc.nextInt();
Connection connection =null;
String sql="select stuId,name,age,sex,adress,birth,tel,Email from Student where stuId=?";
PreparedStatement preparedStatement=null;
ResultSet set=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,stuid);
//執(zhí)行
set = preparedStatement.executeQuery();
while(set.next()){
int id=set.getInt("stuId");
String name=set.getString("name");
int age =set.getInt("age");
String sex =set.getString("sex");
String address=set.getString("adress");
String birth=set.getString("birth");
String tel=set.getString("tel");
String email=set.getString("Email");
System.out.println("\t\t" + id + " \t\t\t" + name
+ " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
" \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
" \t\t\t" + "\n");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(set,preparedStatement,connection);
}
} else if (input==2) {
System.out.print("輸入需要查詢的學生名字:");
String stuname=sc.next();
Connection connection =null;
String sql="select stuId,name,age,sex,adress,birth,tel,Email from Student where name=?";
PreparedStatement preparedStatement=null;
ResultSet set=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1,stuname);
//執(zhí)行
set = preparedStatement.executeQuery();
while(set.next()){
int id=set.getInt("stuId");
String name=set.getString("name");
int age =set.getInt("age");
String sex =set.getString("sex");
String address=set.getString("adress");
String birth=set.getString("birth");
String tel=set.getString("tel");
String email=set.getString("Email");
System.out.println("\t\t" + id + " \t\t\t" + name
+ " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
" \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
" \t\t\t" + "\n");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(set,preparedStatement,connection);
}
}else{
System.out.println(">學生信息顯示\n");
System.out.println("\t --------------------------------------------------------------------------------------------------------");
System.out.println("\t 學號\t\t" + " 姓名\t\t" + " \t年齡\t" + "\t\t性別" + " \t\t\t地址"+
" \t\t\t出生日期"+" \t\t\t電話"+" \t\t\t郵箱" );
System.out.println("\t ------------------------------------------------------------------------------------------------------");
Connection connection =null;
String sql="select * from Student";
PreparedStatement preparedStatement=null;
ResultSet set=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
//執(zhí)行
set = preparedStatement.executeQuery();
while(set.next()){
int id=set.getInt("stuId");
String name=set.getString("name");
int age =set.getInt("age");
String sex =set.getString("sex");
String address=set.getString("adress");
String birth=set.getString("birth");
String tel=set.getString("tel");
String email=set.getString("Email");
System.out.println("\t\t" + id + " \t\t\t" + name
+ " \t\t\t" + age + " \t\t\t" + sex +" \t\t\t" + address +
" \t\t\t" + birth+ " \t\t\t" + tel +" \t\t\t" + email +
" \t\t\t" + "\n");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(set,preparedStatement,connection);
}
System.out.println("\t ------------------------------------" +
"------------------------------------------------------------------");
}
}
查詢學生信息效果圖如下
三、主類的調用?? ?? ??
1、 登錄界面??
首先出現(xiàn)登陸的界面,我們需要輸入我們的用戶名和密碼,然后判斷是否正確
正確的話則執(zhí)行下一步操作?? ?? ??
public static void interFace() throws AWTException {
System.out.println(">首界面\n");
System.out.println("\t*****************************************************************");
System.out.println("\t 首界面 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 開始登錄 請輸入1 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 退出 請輸入0 ");
System.out.println("\t*****************************************************************");
Scanner sc = new Scanner(System.in);
System.out.print("\n請輸入您的選擇: ");
while (true) {
int choose = sc.nextInt();
if (choose == 1) {
register();
break;
} else if (choose == 0) {
System.out.println("退出成功!");
System.exit(0);
} else {
System.out.print("看清選項! 再給你一次機會:");
}
}
}
public static void register() throws AWTException {
for (int i = COUNT; i >= 0; i--) {
Scanner sc = new Scanner(System.in);
System.out.print("請輸入您的用戶名: ");
String loginSid = sc.nextLine();
System.out.print("請輸入您的密碼: ");
String loginPassWd = sc.nextLine();
if (loginSid.equals(MYSID) && loginPassWd.equals(MYPASSWD)) {
Extents.clearConsole();
System.out.println("歡迎登錄! 用戶:" + MYSID + "\n\n");
menu();
break;
} else {
if (i == 0) {
System.out.println("你是不是傻!");
System.exit(0);
}
System.out.println("錯了錯了, 你還有 " + i + " 次機會");
}
}
}
2、 界面搭建????
public static void menu() throws AWTException {
ArrayList<Student> stu = new ArrayList<>();
while (true) {
System.out.println(">首界面>功能界面\n");
System.out.println("\t*****************************************************************");
System.out.println("\t 歡迎來到學生管理系統(tǒng)! ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 1.添加學生信息 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 2.刪除學生信息 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 3.修改學生信息 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t 4.查看學生信息 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.println("\t q:返回上級菜單 p:退出管理系統(tǒng) ");
System.out.println("\t******************************************************************");
Scanner sc = new Scanner(System.in);
System.out.print("\n請輸入您的選擇:");
String choose = sc.nextLine();
switch (choose) {
case "1":
FunctionalBlock.addStu(stu);
break;
case "2":
Extents.clearConsole();
FunctionalBlock.deleteStu(stu);
break;
case "3":
Extents.clearConsole();
FunctionalBlock.updateStu(stu);
break;
case "4":
Extents.clearConsole();
FunctionalBlock.showStu(stu);
Extents.isShow(sc);
break;
case "q":
Extents.clearConsole();
interFace();
return;
case "p":
System.out.println("退出成功!");
System.exit(0);
default:
Extents.clearConsole();
System.out.println("這都錯!看清選項再選\n\n\n");
break;
}
}
}
四、 Extents的相關善后操作?? ?? ?? ??
Extents是完成相關的善后操作,是對FunctionalBlock里面功能實現(xiàn)的相關善后的操作
目的是為了使得更加程序邏輯清晰?? ?? ??
package classSystem;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;
public class Extents {
public static void isAdd(ArrayList<Student> stu, Scanner sc,int stuId ,String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
while (true) {
int is = sc.nextInt();
if (is == 0) {
Extents.clearConsole();
System.out.println("取消成功!");
break;
} else if (is == 1) {
/*Student s = new Student(stuId,name, age,sex,birth, address,tel,email);
stu.add(s);*/
Connection connection =null;
String sql ="insert into Student values(?,?,?,?,?,?,?,?)";
PreparedStatement preparedStatement=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,stuId);
preparedStatement.setString(2,name);
preparedStatement.setInt(3,age);
preparedStatement.setString(4,sex);
preparedStatement.setString(5,address);
preparedStatement.setString(6,birth);
preparedStatement.setString(7,tel);
preparedStatement.setString(8,email);
//執(zhí)行
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(null,preparedStatement,connection);
}
stuId += 1;
Extents.clearConsole();
System.out.println("添加信息成功!\n\n");
FunctionalBlock.showStu(stu);
break;
}
System.out.print("\n輸入錯誤!請重新輸入:");
}
}
public static void isDlete(ArrayList<Student> stu, Scanner sc, int flag) throws AWTException {
while (true) {
int is = sc.nextInt();
if (is == 0) {
Extents.clearConsole();
System.out.println("取消成功!");
break;
} else if (is == 1) {
Connection connection =null;
String sql ="delete from Student where stuId=?";
PreparedStatement preparedStatement=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setInt(1,flag);
//執(zhí)行
preparedStatement.executeUpdate();
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(null,preparedStatement,connection);
}
Extents.clearConsole();
System.out.println("刪除學生信息成功!\n\n");
FunctionalBlock.showStu(stu);
break;
}
System.out.print("\n輸入錯誤!請重新輸入:");
}
}
public static void isUpdata(ArrayList<Student> stu, Scanner sc, int sidUpdate, int flag, String sex,String birth,String tel,String email, String name, int age, String address) throws AWTException {
while (true) {
int is = sc.nextInt();
if (is == 0) {
Extents.clearConsole();
System.out.println("取消成功!");
break;
} else if (is == 1) {
Student newStu = new Student(sidUpdate, name,age,sex,birth,address, tel,email);
Extents.clearConsole();
System.out.println("修改學生信息成功!\n\n");
FunctionalBlock.showStu(stu);
break;
}
System.out.print("\n輸入錯誤!請重新輸入:");
}
}
public static void isShow(Scanner sc) throws AWTException {
System.out.println("\n\n\n>首界面>功能界面>查看學生信息\n\n");
System.out.println("\t 返回上級 請輸入0 ");
System.out.println("\t ---------------------------------------------------------------");
System.out.print("\n請輸入您的選擇: ");
while (true) {
int choose1 = sc.nextInt();
if (choose1 == 0) {
Extents.clearConsole();
break;
} else {
System.out.print("看清選項! 再給你一次機會: ");
}
}
}
public static int getFlag(ArrayList<Student> stu, int sid) {
Connection connection =null;
String sql="select * from Student";
PreparedStatement preparedStatement=null;
ResultSet set=null;
try {
connection = jdbcUtiles.getConnection();
preparedStatement = connection.prepareStatement(sql);
//執(zhí)行
set = preparedStatement.executeQuery();
while(set.next()){
int id =set.getInt("stuId");
if(sid==id){
return id;
}
}
return -1;
} catch (SQLException e) {
throw new RuntimeException(e);
}finally {
jdbcUtiles.close(set,preparedStatement,connection);
}
}
public static void clearConsole() throws AWTException {
Robot r = new Robot();
// 按下Ctrl鍵
r.keyPress(KeyEvent.VK_CONTROL);
// 按下R鍵
r.keyPress(KeyEvent.VK_R);
// 釋放R鍵
r.keyRelease(KeyEvent.VK_R);
// 釋放Ctrl鍵
r.keyRelease(KeyEvent.VK_CONTROL);
r.delay(50);
}
}
五、 數(shù)據(jù)庫的連接?? ???? ?? ?? ??
畢竟我們的這個項目是要連接到數(shù)據(jù)庫當中的
?????♂? ?????♀?所以我們需要手動操作完成數(shù)據(jù)庫連接的相關代碼 ?????♂? ?????♀?
package classSystem;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;
public class jdbcUtiles {
//工具類,連接mysql的連接和關閉
private static String user;
private static String password;
private static String url;
private static String driver;
static {
Properties properties =new Properties();
try {
properties.load(new FileInputStream("src\\mysql.properties"));
//讀取相關屬性
user=properties.getProperty("uesr");
password =properties.getProperty("password");
url=properties.getProperty("url");
driver = properties.getProperty("driver");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//連接數(shù)據(jù)庫
public static Connection getConnection(){
try {
return DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
//關閉相關資源
public static void close(ResultSet set, PreparedStatement preparedStatement,Connection connection){
try {
if(set!=null){
set.close();
}
if(preparedStatement!=null){
preparedStatement.close();
}
if(connection!=null){
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
文章來源:http://www.zghlxwxcb.cn/news/detail-475055.html
六 、感謝與交流?? ?? ?? ?? ?? ??
??????如果大家通過本篇博客收獲了,對通過ava實現(xiàn)學生課程管理系統(tǒng)(數(shù)據(jù)庫)
有了更好的了解的話
那么希望支持一下哦如果還有不明白的,疑惑的話,或者什么比較好的建議的話,可以發(fā)到評論區(qū),
我們一起解決,共同進步 ??????
最后謝謝大家????????????文章來源地址http://www.zghlxwxcb.cn/news/detail-475055.html
到了這里,關于java課程設計(學生信息管理系統(tǒng)設計)+數(shù)據(jù)庫的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!