System.out.println(“Your password is worry!”); }
}

System.out.println(“Login Successful!\n”);
System.out.println(“——————Please choose
option——————\n”
// +”If you want to Change Password ,Please choose 2\n”
+”If you want to Choose Course,Please choose 3\n”+”If you want to Get
Course List,Please choose 4\n”
+”If you want to exit ,Please choose 8\n”);

Statement stat ;
ResultSet rs ;

ManagerMenu1();
}

if(password.equals(managerPass)) {

// System.out.println(ID);

ManagerMenu1();
}

//在开始展览Choose course,Get course list在此以前都务求学员开始展览StuLogin操作

澳门凯旋门游戏网址,//
假若在数据Curry从未找到与用户输入的stuID和Password相相配的stuID和Password,flag则成为false

// 那样写 ,学生选课的数码必须稳固为3门,难题待解决

GetCourseList();
}
else System.out.println(“选课错误”);

}catch(SQLException e) {

ManagerMenu1();
}
澳门凯旋门注册网址,}

}

stat= conn.createStatement();

String couID = null;
String couName = null;
String couTeacher = null;

if( ID.equals(stuID) && stuPassword.equals(Password)) //
注意这里,跳出循环的尺码很注重

String stuID = null;
String Password = null;

// case 2 : ChangePass();break;
case 3 : ChooseCourse();break;
case 4 : GetCourseList();break;
case 10 : System.exit(0);break;
default : System.out.println(“You input an invalid number!”);

System.out.println(“\n Here is student` information \n”);

System.out.println(“The ID or Password is worry!Please input your ID and
Password again\n”);
StuLogin();
}

System.out.println(“———-Student———-\n”);
System.out.println(“Please input option”);
int choose3 = console.nextInt();

System.out.println(“Welcome manager!\n”);
ManagerMenu1();
}

//注意,此处的NewPassword 和 ID 未有要用”括起来

while(rs.next()) {

System.out.println(“\n Please choose your course \n”);

stat = conn.createStatement();
String sql = “select * from stuCourse “;
rs = stat.executeQuery(sql);

/*在此处说Bellamy下 方法execute 、executeQuery、executeUpdate三者的差别
* 方法executeQuery
用于单个结果集的语句,如select。他会把询问的结果放入ResultSet类对象中供役使。
* 方法executeUpdate
用于实行insert、update或delete语句<再次回到值为整数>以及SQL
DDL(数据定义语言),如create table 和 drop table <重回值为零>。
* 方法execute
用于实施回来八个结果集、七个立异计数或双边组合的说话。*/

if(i != 0) {
System.out.println(“成功选入课程”);

/*这里的ID应该必须求重新输入,不然当选择对数据库中有些ID更新的Password实行改动时,未有相应的ID*/

try {
Statement stat = conn.createStatement();
String sql1 = “insert into student(stuID,stuName)
Values(20160501,’徐明正’)”;

String sql1 = “insert into stuCourse(stuID,couID1,couID2,couID3)VALUES(“

// TODO Auto-generated catch block
e.printStackTrace();
}

凯旋门074网址,System.out.println(“———–option————-\n”);

System.out.println(couID + ” ” + couName + ” ” + couTeacher + “\n”);

内部有欠缺应接商酌和指正!

stat = conn.createStatement();
String sql = “select * from student “;
rs = stat.executeQuery(sql);

System.out.println(stuID + ” ” + couID1 + ” ” + couID2 + ” ” + couID3 +
” ” + couID4 + “\n”);

/* 管理员查看学生表 */
public static void GetStudentList() {

ManagerMenu1();
}
}

couID = rs.getString(“couID”);
couName = rs.getString(“couName”);
couTeacher = rs.getString(“couTeacher”);

System.out.println(“\nHere is your course that you have choose\n”);

stat = conn.createStatement();
String sql = “select * from course”;
rs = stat.executeQuery(sql);

int a = stat.executeUpdate(sql1);
System.out.println(“成功增添”+ a + “行学生数量”);
ManagerMenu1();

System.out.println(“Please input your Password”); // 输入密码
String stuPassword = console.next();

链接数据库的代码

Statement stat = null;
ResultSet rs = null;

private static String ID; //
此处的ID设为全局变量,在下边有些方法里会用到
private static Scanner console = new Scanner(System.in);
private static String managerPass = “123456”;
private static Connection conn = xu.getConnection();

/* 管理员查看选课表里的学科*/
public static void GetCourseList1() {

case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
System.out.println(“This is student`s option,try again!”);
ManagerMenu1();
break;
case 6 : CreateStu();break;
case 7 : CreateCourse();break;
case 8 : GetStudentList();break;
case 9 : GetCourseList1();break;
case 10 : System.exit(0);break;
default : System.out.println(“Please input an right number , try
again!”); ManagerMenu1();

 

/*学生修改密码*/
public static void ChangePass() throws SQLException {

System.out.println(“\n Here is course`information \n”);

Statement stat = conn.createStatement();
String sql1 = “insert into
course(couID,couName,couTeacher)values(1,’软件工程’,’黄伟国’)”;
String sql2 = “insert into
course(couID,couName,couTeacher)values(2,’数据库’,’韦美雁’)”;
String sql3 = “insert into
course(couID,couName,couTeacher)values(3,’算法设计’,’黎明先生’)”;
String sql4 = “insert into
course(couID,couName,couTeacher)values(4,’大学土耳其共和国(The Republic of Turkey)语’,’章琴’)”;
String sql5 = “insert into
course(couID,couName,couTeacher)values(5,’Java’,’唐雅媛’)”;

}

break;

stuID = rs.getString(“stuID”);
stuName= rs.getString(“stuName”);

System.out.println(“Welcome Student!”);
StudentMenu1();
}
}

System.out.println(“———-Manager———-\n”);
System.out.println(“Please choose option”);
int choose2 = console.nextInt();

}

try {

Statement stat = null;
ResultSet rs = null;

int a = stat .executeUpdate(sql1);
System.out.println(“成功注册”+ a +”个账号”);

} catch (SQLException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
System.out.println(“Course already exists”);

StudentMenu1();

System.out.println(couID + ” ” + couName + ” ” + couTeacher);
}

// 这里对学生音信的输入也亟须二个多少个输入,那是系统的后天不足,难题待化解

链接数据库的代码。else System.out.println(“\n”+”Changing the Password is failed!”);

int sum = a + b + c + d + e;
System.out.println(“成功增加”+ sum + “行课程数据”);
ManagerMenu1();

stuID = rs.getString(“stuID”);
couID1 = rs.getString(“couID1”);
couID2 = rs.getString(“couID2”);
couID3 = rs.getString(“couID3”);
couID4 = rs.getString(“couID4”);

public class test1{

/*学生操作菜单*/
public static void StudentMenu1() throws SQLException {

else if(choose1 == 0) {

}catch(SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

} catch (SQLException e) {

switch(choose2) {

if(stuID.equals(ID))

System.out.println(“Welcome to the student selection system!\链接数据库的代码。n\n”
+”if you are maneger please choose 6、7、8、9、10\n”
+”if you are student Please choose 1、2、3、4、5、10\n”);
ShowMenu();
}

System.out.println(“Please input your ID “);
String ID = console.next();
System.out.println(“Please input your Password”);
String Password = console.next();

else {
System.out.println(“***”+ID+”***”+stuID
+”***”+stuPassword+”***”+Password+”***”);

}
}

System.out.println(ID);
String couID = null;
String couName = null;
String couTeacher = null;

System.out.println(“1–Student login”); // 学生登入
System.out.println(“2–Change password”); // 学生修改密码
System.out.println(“3–Choose course”); // 学生选课
System.out.println(“4–Get course list”); // 学生查看本身的课表
System.out.println(“5–Student rigistration”); // 学生注册账号
System.out.println(“6–Create student”); // 管理员创立学生
System.out.println(“7–Create course”); // 管理员创立课表
System.out.println(“8–Get student list”); // 助理馆员查看学生表
System.out.println(“9–Get course list1”); // 管理员查看选课表里的教程
System.out.println(“10–exit\n”); // 退出

package connection;
//连接数据库student

StudentMenu1();
}

case 1 : StuLogin();break;
case 2 : ChangePass();break;

if(choose1 == 1) {

 

public static void ShowMenu() throws SQLException {

System.out.println(“成功修改”+a+”行记录”);
System.out.println(“Your new Password is “+ NewPassword);

while(rs.next()) {

}catch(SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/*管理员操作菜单*/
public static void ManagerMenu1() throws SQLException {

// String sql1 =”UPDATE login SET Password = 111 where stuID =
20156022″;

  • ID + “,”+ ID1 + “,” + ID2 + “,” +ID3 +”)”;
    int i = stat.executeUpdate(sql1);

}

链接数据库的代码。else {

if(!flag){ // 当flag 为 false 时

String stuID = null;
String stuName = null;

// TODO Auto-generated catch block
链接数据库的代码。e.printStackTrace();
}

switch(choose4) {

System.out.println(“manager choose 1 ,student choose 0”);
int choose1 = console.nextInt(); //int 用nextInt()

switch(choose3) {

while(rs.next()) {

Statement stat = null;
ResultSet rs = null;

//
此处stuID固定位学生登入时所用的ID,那样能够确认保障登入本人的账号却能选其余账号的课程

int choose4 = console.nextInt();

 

System.out.println(“Please input your stuID”); // 输入账号
ID = console.next();

try {

try {

public static void Test() throws SQLException {

/*学生登陆*/
public static void StuLogin() throws SQLException {

链接数据库的代码。public static void main(String [] args) throws SQLException {

/*学员登记*/
public static void StuRigistration() throws SQLException{

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}catch(SQLException e) {
// TODO Auto-generated catch block
System.out.println(“The student already exists”);

private static Connection conn = null;
static {
try {
// 注册驱动
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
// 拿到一个数据库连接
conn =
DriverManager.getConnection(“jdbc:sqlserver://localhost:1433;DatabaseName=student”,”sa”,”123456″);
}catch(ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

while(flag = rs.next()) { // rs.next(); //重临值为true or false

case 3 :
case 4 : System.out.println(“you must login before you can do
it!\n”);StuLogin();break;
case 5 : StuRigistration();break;
case 6 :
case 7 :
case 8 :
case 9 : System.out.println(“This is manager`s option,try
again!”);StudentMenu1();break;
case 10 : System.exit(0);break;
default : System.out.println(“Please input an right number,try
again!”);StudentMenu1();

try {
Statement stat = conn.createStatement();
String sql1 = “insert into login(stuID,Password)Values(” + ID + “, ” +
Password + “)”;
//这里密码只可以输入数字,难题待化解

stat = conn.createStatement();
String sql = “select * from course “;
rs = stat.executeQuery(sql);

/*学生得到已选课程列表*/
public static void GetCourseList() throws SQLException {

}
}

System.out.println(“——–可选课程的信息——-“);
while(rs.next()) {

try {

}catch(SQLException e) {
// TODO Auto-generated catch block
System.out.println(“ID already exists”);
}
}

try {
stat = conn.createStatement();
String sql1 = “select * from login “; /*
从login表中询问其颇具属性值,则stuID 和 Password皆有了。
rs是结果集。查询出的记录是壹个列表,起首时指针指向的是率先条记下从前的。*/
boolean flag;
rs = stat.executeQuery(sql1);

}

public class xu{

}

System.out.println(“Please input your password :”);
String password = console.next(); //String 用next()

那边运用JAVA语言编写的简要的学员选课系统,呈现的都以以此系统核心代码。

/*组织者创立学生*/
public static void CreateStu() throws SQLException {

stat = conn.createStatement(); // 二种写法都得以
// stat =
conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql =”UPDATE login SET Password =” + “” + NewPassword + ” where
stuID =”+ ID;

if(a != 0) {

选课的操作代码

/*协会者创设课程*/
public static void CreateCourse() throws SQLException{

}catch(SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

import java.sql.*;
import java.util.*;

/*学员选课*/
public static void ChooseCourse() throws SQLException {

Test();
}

System.out.println(“input CourseID”);
int ID1 = console.nextInt();
int ID2 = console.nextInt();
int ID3 = console.nextInt();

System.out.println(stuID + ” ” + stuName + “\n”);

try {
/* 通过connection数据库链接对象
创造二个statement对象数据库操作对象,stat对象再取得三个施行sql的言辞。
* stat对象便是java程序与Database的一个三番五次通道*/

stuID = rs.getString(“stuID”);
Password = rs.getString(“Password”);

package connection;

try {

int a = stat.executeUpdate(sql1);
int b = stat.executeUpdate(sql2);
int c = stat.executeUpdate(sql3);
int d = stat.executeUpdate(sql4);
int e = stat.executeUpdate(sql5);

int a = stat.executeUpdate(sql);
System.out.println(a);

Statement stat ;

Statement stat;
ResultSet rs;

String stuID = null;
String couID1 = null;
String couID2 = null;
String couID3 = null;
String couID4 = null;

public static Connection getConnection() {
return conn;
}
}

import java.sql.Connection;
import java.sql.DriverManager;
//import java.sql.Statement;
import java.sql.SQLException;

System.out.println(“Please input your ID”);
String ID = console.next();
System.out.println(“Please input your new Password”);
String NewPassword = console.next();

couID = rs.getString(“couID”);
couName = rs.getString(“couName”);
couTeacher = rs.getString(“couTeacher”);

相关文章