您的位置:新葡亰496net > 网络数据库 > 新葡亰496net:增删改查,电话薄设计

新葡亰496net:增删改查,电话薄设计

发布时间:2019-09-15 20:19编辑:网络数据库浏览(184)

    此地运用JAVA语言编写的大致的上学的儿童选课系统,表现的都是以此系统宗旨代码。

    package com.hanqi.telbook;

    package com.db.conn;

    1.方法类

    1.方法类

    内部有不足迎接批评和指正!

    import java.util.Scanner;

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

    package com.com;

    package com.com;

     

    public class Menu {
    //主菜单

    public class ConOracl {

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

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

    链接数据库的代码

    public void mainMenu()
    {

    // 数据库驱动类
    private String dbDriver = "oracle.jdbc.driver.OracleDriver";
    // 连接数据库url
    private String dbURL = "jdbc:oracle:thin:@localhost:1521:xe";
    // 连接数据库客商名
    private String dbUser = "system";
    // 连接数据库密码
    private String dbPwd = "123";
    // 获取数据库连接格局, 重返Connection对象
    private Connection con = null;
    //数据施行语句
    private Statement  stat = null;
    private String sql=null;
    private ResultSet rs=null;
    //创立数据库连接
    public Connection getDBConnect() {
    try {
    // 加载数据库驱动
    Class.forName(dbDriver);
    con = DriverManager.getConnection(dbURL, dbUser, dbPwd);
    } catch (Exception e) {
    System.out.println(e);
    }
    return con;
    }
    //增加
    public void Add()
    {
    con=getDBConnect();
    sql="insert into student(stuno,stuname,stusex)"
    "values('1','lucy','w')";
    try {
    新葡亰496net:增删改查,电话薄设计。stat=con.createStatement();
    stat.executeUpdate(sql);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    //删除
    public void Delete()
    {
    con=getDBConnect();
    sql="delete  from student "
    "where stuno=1";
    try {
    stat=con.createStatement();
    stat.executeUpdate(sql);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

     

     

    package connection;
    //连接数据库student

    System.out.println("**************************");
    System.out.println("** 1 增多记录 **");
    System.out.println("** 2 查找记录 **");
    System.out.println("** 3 修改记录 **");
    System.out.println("** 4 删除记录 **");
    System.out.println("** 5 排序记录 **");
    System.out.println("** 6 退出记录 **");
    System.out.println("**************************");
    System.out.println("请输入精确的数字,最小是:1,最大是:6");

    }
    //修改
    public void Update()
    {
    con=getDBConnect();
    sql="update student set stuname='ben' where stuno='2'";
    try {
    stat=con.createStatement();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    //查询
    public void Search() {
    con = getDBConnect();
    // 创造表的sql语句
    sql = "SELECT * FROM student";
    try {
    stat = con.createStatement();
    rs= stat.executeQuery(sql);
    while (rs.next()) {
    String stuno = rs.getString(1);
    String stuname = rs.getString(2);
    String stusex = rs.getString(3);
    System.out.println(stuno "," stuname "," stusex);
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    //功效:关闭数据库的连接
     
        public void close() {//6.释放财富
          try { // 捕捉十分
               try {
                   if (rs!= null) { // 当ResultSet对象的实例rs不为空时
                    rs.close(); // 关闭ResultSet对象
                  }
                } finally {
                  try {
                        if (stat != null) { // 当Statement对象的实例stmt不为空时
                        stat.close(); // 关闭Statement对象
                        }
                  } finally {
                       if (con!= null) { // 当Connection对象的实例conn不为空时
                            con.close(); // 关闭Connection对象
                    }
                  }
             }
           } catch (Exception e) {
               e.printStackTrace(System.err); // 输出至极音信
           }
       }
    public static void main(String[] args) {
    ConOracl oracl = new ConOracl();
    System.out.println("操作从前:");
    oracl.Search();
    oracl.Add();
    oracl.Delete();
    oracl.Update();
    System.out.println("操作之后:");
    oracl.Search(); 
    oracl.close();
    }
    }

    public class tool {

    public class tool {

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

    }
    //增多客户菜单
    public void addMenu()
    {

    /**
    * @throws Exception
    */
    static Connection conn =null;
    static Statement st =null;
    static ResultSet rs =null;
    public static void mains() {

    /**
    * @throws Exception
    */
    static Connection conn =null;
    static Statement st =null;
    static ResultSet rs =null;
    public static void mains() {

    public class xu{

    System.out.println("**************************");
    System.out.println("** 1 加多新记录 **");
    System.out.println("** 2 查看全记录 **");
    System.out.println("** 3 再次来到上一流 **");
    System.out.println("**************************");
    System.out.println("请输入正确的数字,最小是:1,最大是:3");

    try{
    Class.forName("oracle.jdbc.OracleDriver");
    conn =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","mysql","123456");
    st=conn.createStatement();
    rs=st.executeQuery("select numno,ename from dept");

    try{
    Class.forName("oracle.jdbc.OracleDriver");
    conn =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/XE","mysql","123456");
    st=conn.createStatement();
    rs=st.executeQuery("select numno,ename from dept");

    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();
    }
    }

    }
    //查找顾客菜单
    public int searchMenu()
    {int rst=0;
    System.out.println("**************************");
    System.out.println("** 1 按姓名查找 **");
    System.out.println("** 2 按年龄查找 **");
    System.out.println("** 3 按性别查找 **");
    System.out.println("** 4 按编号查找 **");
    System.out.println("** 5 按住址查找 **");
    System.out.println("** 6 查看全记录 **");
    System.out.println("** 7 再次回到上顶级 **");
    System.out.println("**************************");
    System.out.println("请输入准确的数字,最小是:1,最大是:7");

    while (rs.next()) {
    System.out.println(rs.getInt("numno") "---" rs.getString("ename"));
    }

    while (rs.next()) {
    System.out.println(rs.getInt("numno") "---" rs.getString("ename"));
    }

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

    Scanner sc=new Scanner(System.in );

    }catch (Exception e) {
    e.printStackTrace();
    }/*finally {
    try {
    if (rs != null)
    rs.close();
    if (st != null)
    st.close();
    if (conn != null)
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }*/
    }
    //增多数据
    public static void add(String num1, String name1) throws SQLException{
    int addRe=st.executeUpdate("insert into dept (numno,ename) values (" num1 ",'" name1 "')");
    System.out.println("******丰裕操作结果是:" addRe);

    }catch (Exception e) {
    e.printStackTrace();
    }/*finally {
    try {
    if (rs != null)
    rs.close();
    if (st != null)
    st.close();
    if (conn != null)
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }*/
    }
    //增多数据
    public static void add(String num1, String name1) throws SQLException{
    int addRe=st.executeUpdate("insert into dept (numno,ename) values (" num1 ",'" name1 "')");
    System.out.println("******增进操作结果是:" addRe);

     

    while(true)
    { try{
    rst=sc.nextInt();
    if(rst>=1&&rst<=7)
    {
    break;
    }
    else
    {
    System.out.println("输入错误,重新选择:");
    }
    }

    }
    //删除数据
    public static void delete(String num2) throws SQLException{
    int dele=st.executeUpdate("delete from dept where numno=" num2 "");
    System.out.println("******去除操作结果是:" dele);
    }
    //修改数据
    public static void alters(String num3, String name2) throws SQLException{
    int alt=st.executeUpdate("update dept set ename='" name2 "'where numno=" num3 "");
    System.out.println("******剔除操作结果是:" alt);

    }
    //删除数据
    public static void delete(String num2) throws SQLException{
    int dele=st.executeUpdate("delete from dept where numno=" num2 "");
    System.out.println("******删除操作结果是:" dele);
    }
    //修改数据
    public static void alters(String num3, String name2) throws SQLException{
    int alt=st.executeUpdate("update dept set ename='" name2 "'where numno=" num3 "");
    System.out.println("******删去操作结果是:" alt);

     

    catch(Exception e)
    {
    System.out.println("输入非法,请重新输入:");
    }
    break;
    }
    return rst;
    }
    //修改顾客消息主菜单
    public void modifyMenu()
    {
    System.out.println("**************************");
    System.out.println("** 1 查看全记录 **");
    System.out.println("** 2 修改内定记录 **");
    System.out.println("** 3 重回上一流 **");
    System.out.println("**************************");
    System.out.println("请输入准确的数字,最小是:1,最大是:3");
    }
    //修改顾客音信子菜单
    public int subModifyMenu()
    {
    int rst=0;
    System.out.println("**************************");
    System.out.println("** 1 修改姓名 **");
    System.out.println("** 2 修改年龄 **");
    System.out.println("** 3 修改性别 **");
    System.out.println("** 4 修改号码 **");
    System.out.println("** 5 修改住址 **");
    System.out.println("** 6 重回上一流 **");
    System.out.println("**************************");
    System.out.println("请输入精确的数字,最小是:1,最大是:6");
    Scanner sc=new Scanner(System.in );
    while(true)
    {
    rst=sc.nextInt();
    if(rst>=1&&rst<=6)
    {
    break;
    }
    else
    {
    System.out.println("输入错误,重新选用:");
    }
    }

    }

    }

    选课的操作代码

    return rst;

    }

    }

    package connection;

    }
    //删除顾客音讯菜单
    public int deleteMenu()
    {
    int rst=0;
    System.out.println("**************************");
    System.out.println("** 1 查看全记录 **");
    System.out.println("** 2 删除钦定记录 **");
    System.out.println("** 3 删除全数记录 **");
    System.out.println("** 4 重临上顶尖 **");
    System.out.println("**************************");
    System.out.println("请输入精确的数字,最小是:1,最大是:4");
    Scanner sc=new Scanner(System.in );

     

     

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

    while(true)
    {
    rst=sc.nextInt();
    if(rst>=1&&rst<=4)
    {
    break;
    }
    else
    {
    System.out.println("输入错误,重新选拔:");
    }
    }

    2.调用类(执行类,测试类)

    2.调用类(执行类,测试类)

    public class test1{

    return rst;
    }
    //排序客户消息菜单
    public int orderMenu()
    {
    int rst=0;
    System.out.println("**************************");
    System.out.println("** 1 按姓名排序 **");
    System.out.println("** 2 按年龄排序 **");
    System.out.println("** 3 按性别排序 **");
    System.out.println("** 4 查看全部记录 **");
    System.out.println("** 5 再次来到上一流 **");
    System.out.println("**************************");
    System.out.println("请输入精确的数字,最小是:1,最大是:5");
    Scanner sc=new Scanner(System.in );

    import java.sql.SQLException;
    import java.util.Scanner;

    import java.sql.SQLException;
    import java.util.Scanner;

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

    while(true)
    {
    rst=sc.nextInt();
    if(rst>=1&&rst<=5)
    {
    break;
    }
    else
    {
    System.out.println("输入错误,重新选拔:");
    }
    }

    public class test {

    public class test {

    public static void main(String [] args) throws SQLException {

    return rst;
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    Scanner sca = new Scanner(System.in);
    boolean flag = true;
    while (flag) {
    System.out.println(" 1.添加 2.删除 3.修改 4.退出 ");
    int num = 0;

    /**
    * @param args
    */
    public static void main(String[] args) {
    Scanner sca = new Scanner(System.in);
    boolean flag = true;
    while (flag) {
    System.out.println(" 1.添加 2.删除 3.修改 4.退出 ");
    int num = 0;

    System.out.println("Welcome to the student selection system!nn"
    "if you are maneger please choose 6、7、8、9、10n"
    "if you are student Please choose 1、2、3、4、5、10n");
    ShowMenu();
    }

    public void start() throws Exception
    {
    while(true)
    {
    TelNoteRegex tnr=new TelNoteRegex();
    Operate op=new Operate();
    int i=tnr.menuRegex(1, 6);
    switch(i)
    {//添加
    case 1:
    addMenu();
    tnr.addmenu(1, 3);
    break;
    //查找
    case 2:

    try {
    num = sca.nextInt();
    } catch (Exception e) {
    System.out.println("异常");
    break;
    }

    try {
    num = sca.nextInt();
    } catch (Exception e) {
    System.out.println("异常");
    break;
    }

    public static void ShowMenu() throws SQLException {

    op.searchLogic();
    break;
    //修改
    case 3:

    switch (num) {
    case 1:
    System.out.println("增加前的多寡");
    tool.mains();
    System.out.println("请输入您增加的号码:");
    String num1 = sca.next();
    //保障输入的是数字
    for (int i = num1.length(); --i >= 0;) {
    int nums = num1.charAt(i);
    if (num1.length() == 4 && nums >= 48 && nums <= 57) {

    switch (num) {
    case 1:
    System.out.println("增加前的多寡");
    tool.mains();
    System.out.println("请输入您增加的号码:");
    String num1 = sca.next();
    //有限支撑输入的是数字
    for (int i = num1.length(); --i >= 0;) {
    int nums = num1.charAt(i);
    if (num1.length() == 4 && nums >= 48 && nums <= 57) {

    System.out.println("-----------option-------------n");

    op.modifyLogicLogic();
    break;
    //删除
    case 4:

    System.out.println("请输入您加多的名号:");
    String name1 = sca.next();

    System.out.println("请输入您增加的称谓:");
    String name1 = sca.next();

    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--exitn"); // 退出

    op.deleteLogic();
    break;
    //排序
    case 5:
    op.orderLogic();
    break;
    //退出
    case 6:

    try {
    tool.add(num1, name1);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("增加后的数量--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    try {
    tool.add(num1, name1);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("增多后的数据--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    Test();
    }

    break;

    break;
    //删除数据
    case 2:
    System.out.println("删除前的数据");
    tool.mains();
    System.out.println("请输入您删除的数码:");
    String num2 = sca.next();
    //数字
    for (int i = num2.length(); --i >= 0;) {
    int nums1 = num2.charAt(i);
    if (num2.length() == 4 && nums1 >= 48 && nums1 <= 57) {
    try {
    tool.delete(num2);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("删除后的多少--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    break;
    //删除数据
    case 2:
    System.out.println("删除前的多寡");
    tool.mains();
    System.out.println("请输入您删除的数码:");
    String num2 = sca.next();
    //数字
    for (int i = num2.length(); --i >= 0;) {
    int nums1 = num2.charAt(i);
    if (num2.length() == 4 && nums1 >= 48 && nums1 <= 57) {
    try {
    tool.delete(num2);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("删除后的数额--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    public static void Test() throws SQLException {

    default:
    break;

    break;
    case 3:
    //修改数据
    System.out.println("修改前的数额");
    tool.mains();
    System.out.println("请输入您修改的数码:");

    break;
    case 3:
    //修改数据
    System.out.println("修改前的数额");
    tool.mains();
    System.out.println("请输入您修改的号子:");

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

    }
    if(i==6)

    String num3 = sca.next();
    //数字
    for (int i = num3.length(); --i >= 0;) {
    int nums2 = num3.charAt(i);
    if (num3.length() == 4 && nums2 >= 48 && nums2 <= 57) {
    System.out.println("请输入您修改的称呼:");
    String name2 = sca.next();
    try {
    tool.alters(num3, name2);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("修改后的数额--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    String num3 = sca.next();
    //数字
    for (int i = num3.length(); --i >= 0;) {
    int nums2 = num3.charAt(i);
    if (num3.length() == 4 && nums2 >= 48 && nums2 <= 57) {
    System.out.println("请输入您修改的名称:");
    String name2 = sca.next();
    try {
    tool.alters(num3, name2);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    System.out.println("修改后的多少--");
    tool.mains();
    i=-i;
    } else {
    System.out.println("输入内容有误,请输入4位数数字");
    break;
    }
    }

    if(choose1 == 1) {

    break;

    break;
    case 4:
    System.out.println("您已脱离系统!");
    flag = false;
    break;

    break;
    case 4:
    System.out.println("您已退出系统!");
    flag = false;
    break;

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

    }
    }
    }

    default:
    System.out.println("请输入规定的数字!");
    break;
    }

    default:
    System.out.println("请输入规定的数字!");
    break;
    }

    if(password.equals(managerPass)) {

    package com.hanqi.telbook;
    import java.util.Scanner;

    }

    }

    System.out.println("Welcome manager!n");
    ManagerMenu1();
    }

    public class TelNoteRegex {
    //对菜单输入选项的求证

    }

    }

    else {

    public int menuRegex (int min, int max )
    {
    int scc=0;
    try{
    Menu me=new Menu();

    }

    }

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

    Scanner sc =new Scanner(System.in);
    while(true)
    {
    me.mainMenu();
    int i=sc.nextInt();
    if(i>=min&&i<=max&&i%1==0)
    {
    scc=i;
    break;
    }
    }
    }

    else if(choose1 == 0) {

    catch(Exception e)
    {
    System.out.println("输入的数字非法");

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

    }
    return scc;
    }
    //增加客商的子菜单
    public int addmenu(int min,int max)throws Exception
    {
    int scc=0;
    try{
    TelNoteRegex tnr=new TelNoteRegex();
    Operate op=new Operate();
    Scanner sc =new Scanner(System.in);
    while(true)
    {

    /*领队操作菜单*/
    public static void ManagerMenu1() throws SQLException {

    int i=sc.nextInt();

    System.out.println("----------Manager----------n");
    System.out.println("Please choose option");
    int choose2 = console.nextInt();

    if(i>=min&&i<=max&&i%1==0)
    {
    scc=i;
    switch(i)
    {
    case 1:
    op.addOperation();
    break;
    case 2:
    op.showAll();

    switch(choose2) {

    break;
    case 3:
    Menu mee=new Menu();
    mee.start();
    break;
    default:
    break;
    }

    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();

    return scc;

    }
    }

    }
    break;
    }
    }
    catch(Exception e)
    {
    System.out.println("输入的数字违规");

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

    }
    return scc;
    }
    //对顾客输入人名的印证
    public String nameRegex()
    {
    String name="";
    while(true)
    {
    Scanner sc =new Scanner(System.in);
    System.out.println("输入人名:1-十人字母");
    String str=sc.nextLine();
    if(str.matches("[a-zA-Z]{1,10}"))
    {
    name=str;
    break;
    }
    }
    return name;
    }
    //对客商输入年龄的注解
    public int ageRegex()
    {
    int age=0;
    while(true)
    {
    Scanner sc =new Scanner(System.in);
    System.out.println("输入年龄,1-100 ");
    int ii=sc.nextInt();
    if(ii>0&&ii<=100)
    {
    age=ii;
    break;
    }
    }
    return age;
    }
    // 对客户输入性其余辨证
    public String sexRegex()
    {
    String sex="";
    while(true)
    {
    Scanner sc =new Scanner(System.in);
    System.out.println("输入性别,(男 m or M)(女 f or F)");
    String str=sc.nextLine();
    if(str.equals("男")||str.equals("m")||str.equals("M")
    ||str.equals("女")||str.equals("f")||str.equals("F"))
    {
    sex=str;
    break;

    System.out.println("----------Student----------n");
    System.out.println("Please input option");
    int choose3 = console.nextInt();

    }
    }
    return sex;
    }
    //对客商输入电话号码的验证
    public String telNumRegex()
    {
    String tel="";
    while(true)
    {
    Scanner sc =new Scanner(System.in);
    System.out.println("输入电话号码,6-12位数字");
    String tell=sc.nextLine();
    if(tell.matches("[0-9]{6,10}"))
    {
    tel=tell;
    break;
    }
    }
    return tel;
    }
    //对客商输入地方的认证
    public String addressRegex()
    {
    String add="";

    switch(choose3) {

    while(true)
    {
    Scanner sc =new Scanner(System.in);
    System.out.println("输入地方,1-五11人字母或数字");
    String str=sc.nextLine();
    if(str.matches("[A-Za-z0-9]{1,50}"))
    {
    add=str;
    break;
    }
    }
    return add;
    }

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

    }

    //在开展Choose course,Get course list此前都务求学生开展StuLogin操作

    package com.hanqi.telbook;

    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();

    public class Person {
    private int id;
    private String name;
    private int age;
    private String sex;
    private String telnum;
    private String address;
    public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }
    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 getSex() {
    return sex;
    }
    public void setSex(String sex) {
    this.sex = sex;
    }
    public String getTelnum() {
    return telnum;
    }
    public void setTelnum(String telnum) {
    this.telnum = telnum;
    }
    public String getAddress() {
    return address;
    }
    public void setAddress(String address) {
    this.address = address;
    }

    }
    }

    public Person(String name, int age, String sex, String telnum, String address) {
    super();
    this.name = name;
    this.age = age;
    this.sex = sex;
    this.telnum = telnum;
    this.address = address;
    }
    public Person() {
    super();
    }
    @Override
    public String toString() {
    return "Person [序号=" id ", 姓名=" name ", 年龄=" age ", 性别=" sex ", 电话号码=" telnum

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

    • ", 地址=" address "]";
      }

    try {
    /* 通过connection数据库链接对象 创设二个statement对象数据库操作对象,stat对象再赢得一个实践sql的言辞。
    * stat对象就是java程序与Database的贰个接二连三通道*/

    }

    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,'算法设计','黎明(英文名:lí míng)')";
    String sql4 = "insert into course(couID,couName,couTeacher)values(4,'大学印度语印尼语','章琴')";
    String sql5 = "insert into course(couID,couName,couTeacher)values(5,'Java','唐雅媛')";

    package com.hanqi.telbook;

    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);

    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    import com.mchange.v2.c3p0.ComboPooledDataSource;

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

    public class Operate {

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

    ComboPooledDataSource cp=new ComboPooledDataSource("helloc3p0");
    //list 集合
    private List<Person> ls= new ArrayList<>();

    ManagerMenu1();
    }
    }

    //顾客增进消息事业逻辑调整
    public void addLogic()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    //配置连接池
    try {

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

    Connection conn=cp.getConnection();
    String sql="insert into person values(sq_person.nextval,?,?,?,?,?)";
    PreparedStatement ps= conn.prepareStatement(sql);

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

    ps.setString(1, tnr.nameRegex());
    ps.setInt(2, tnr.ageRegex());
    ps.setString(3, tnr.sexRegex());
    ps.setString(4, tnr.telNumRegex());
    ps.setString(5, tnr.addressRegex());
    ps.executeUpdate();
    System.out.println("增加账户成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    }
    //客户查询音讯工作逻辑调控
    public List<Person> searchLogic() throws Exception
    {
    Menu me=new Menu();
    List<Person> p=null;
    switch(me.searchMenu())
    {
    case 1:
    searchByName();

    // 这里对学员音信的输入也亟须叁个八个输入,那是系统的恶疾,难题待消除

    break;
    case 2:
    searchByAge();

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

    break;
    case 3:
    searchBySex();

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

    break;
    case 4:
    searchByTelNum();

    ManagerMenu1();
    }
    }

    break;
    case 5:
    searchByAdd();

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

    break;
    case 6:
    showAll();

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

    break;
    case 7:

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

    break;

    String stuID = null;
    String Password = null;

    default:
    break;
    }

    Statement stat ;
    ResultSet rs ;

    return p;
    }

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

    //修改消息职业逻辑调整
    public void modifyLogicLogic() throws Exception
    {
    try{
    Menu me=new Menu();
    me.modifyMenu();
    Scanner sc=new Scanner(System.in);
    int i=sc.nextInt();
    if(i==1)
    {
    showAll();
    }
    else if(i==2)
    {Menu mee=new Menu();

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

    switch(mee.subModifyMenu())
    {
    case 1:

    stuID = rs.getString("stuID");
    Password = rs.getString("Password");

    Scanner sc2=new Scanner(System.in);

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

    System.out.println("请输入须求修改的ID号");
    int id=sc2.nextInt();
    modifyname( id);
    break;
    case 2:

    break;

    Scanner sc3=new Scanner(System.in);

    // 假如在数据Curry未有找到与客户输入的stuID和Password相相称的stuID和Password,flag则成为false

    System.out.println("请输入须要修改的ID号");
    int id1=sc3.nextInt();
    modifyage( id1);
    break;
    case 3:

    }

    Scanner sc4=new Scanner(System.in);

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

    System.out.println("请输入需求修改的ID号");
    int id2=sc4.nextInt();

    System.out.println("The ID or Password is worry!Please input your ID and Password againn");
    StuLogin();
    }

    modifysex(id2);
    break;
    case 4:

    else {
    System.out.println("***" ID "***" stuID "***" stuPassword "***" Password "***");

    Scanner sc5=new Scanner(System.in);

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

    System.out.println("请输入必要修改的ID号");
    int id3=sc5.nextInt();
    modifytelnum( id3);
    break;
    case 5:

    int choose4 = console.nextInt();

    Scanner sc6=new Scanner(System.in);

    switch(choose4) {

    System.out.println("请输入要求修改的ID号");
    int id4=sc6.nextInt();
    modifyaddress( id4);
    break;
    case 6:
    modifyLogicLogic();
    break;

    // 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!");

    }
    }

    }

    else if(i==3)
    {

    }

    me.start();

    } catch (SQLException e) {

    }
    }
    catch(Exception e)
    {
    System.out.println("输入违法,请重新输入!");
    }
    }

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

    //删除消息专门的学问逻辑调控
    public void deleteLogic() throws Exception
    {
    Menu menu=new Menu();
    while(true)
    {

    }

    switch(menu.deleteMenu())
    {
    case 1:
    showAll();

    /*在此处说雅培(Abbott)(Karicare)下 方法execute 、executeQuery、executeUpdate三者的区分
    * 方法executeQuery 用于单个结果集的话语,如select。他会把询问的结果放入ResultSet类对象中供役使。
    * 方法executeUpdate 用于实践insert、update或delete语句<重临值为整数>以及SQL DDL(数据定义语言),如create table 和 drop table <重回值为零>。
    * 方法execute 用于实施回来两个结果集、四个更新计数或双边组合的说话。*/

    break;
    case 2:
    delete();
    break;
    case 3:
    deleteAll();
    break;
    case 4:

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

    menu.start();
    break;
    default:
    System.out.println("输入不科学");
    break;
    }

    // System.out.println(ID);

    }
    }
    //排序新闻工作逻辑调整
    public List<Person> orderLogic() throws Exception
    {

    /*这里的ID应该须要求重新输入,否则当接纳对数据库中有个别ID更新的Password实行更改时,未有对应的ID*/

    Menu menu=new Menu();
    while(true)
    {
    switch(menu.orderMenu())
    {
    case 1:
    orderName();

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

    break;
    case 2:
    orderAge();

    Statement stat ;

    break;
    case 3:
    orderSex();

    try {

    break;
    case 4:
    showAll();

    stat = conn.createStatement(); // 三种写法都足以
    // stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    String sql ="UPDATE login SET Password =" "" NewPassword " where stuID =" ID;

    break;
    case 5:
    menu.start();
    break;
    default:
    System.out.println("输入错误");
    break;
    }
    }
    }
    //加多新客商音讯
    public void addOperation()
    {
    Operate or= new Operate();
    or.addLogic();
    }
    //查询任何客户新闻
    public List<Person> showAll()
    {
    try {
    Connection conn= cp.getConnection();

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

    Statement st=conn.createStatement();
    String sql="select * from person";
    ResultSet rs=st.executeQuery(sql);
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

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

    ls.add(bc);
    }
    for(Person p1:ls)
    {
    System.out.println(p1);
    }

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

    rs.close();
    st.close();
    conn.close();

    if(a != 0) {

    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按姓名查询客户音讯
    public List<Person> searchByName()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="select * from person where name=?";
    try {
    Connection conn= cp.getConnection();

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

    PreparedStatement ps=conn.prepareStatement(sql);
    ps.setString(1, tnr.nameRegex());
    ResultSet rs=ps.executeQuery();
    //遍历结果集

    StudentMenu1();
    }

    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

    else System.out.println("n" "Changing the Password is failed!");

    ls.add(bc);
    }

    }catch(SQLException e) {

    for(Person p1:ls)
    {
    System.out.println(p1);
    }
    if(!rs.next())
    {
    System.out.println("数据库未有相关资料");
    }
    rs.close();
    ps.close();
    conn.close();

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

    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;

    }

    }
    //按年龄查询客户消息
    public List<Person> searchByAge()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="select * from person where age=?";
    try {
    Connection conn= cp.getConnection();

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

    PreparedStatement ps=conn.prepareStatement(sql);
    ps.setInt(1, tnr.ageRegex());
    ResultSet rs=ps.executeQuery();
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

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

    ls.add(bc);
    }
    for(Person p1:ls)
    {
    System.out.println(p1);
    }
    if(!rs.next())
    {
    System.out.println("数据库没有相关资料");
    }
    rs.close();
    ps.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按性别查询客商消息
    public List<Person> searchBySex()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="select * from person where sex=?";
    try {
    Connection conn= cp.getConnection();

    Statement stat;
    ResultSet rs;

    PreparedStatement ps=conn.prepareStatement(sql);
    ps.setString(1, tnr.sexRegex());
    ResultSet rs=ps.executeQuery();
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

    try {

    ls.add(bc);
    }
    for(Person p1:ls)
    {
    System.out.println(p1);
    }
    if(!rs.next())
    {
    System.out.println("数据库未有有关材质");
    }
    rs.close();
    ps.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按电话号码查询客商信息
    public List<Person> searchByTelNum()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="select * from person where telnum=?";
    try {
    Connection conn= cp.getConnection();
    PreparedStatement ps=conn.prepareStatement(sql);
    ps.setString(1,tnr.telNumRegex());
    ResultSet rs=ps.executeQuery();
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

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

    ls.add(bc);
    }
    for(Person p1:ls)
    {
    System.out.println(p1);
    }
    if(!rs.next())
    {
    System.out.println("数据库未有相关资料");
    }
    rs.close();
    ps.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按地址询问客商信息
    public List<Person> searchByAdd()
    {
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="select * from person where address=?";
    try {
    Connection conn= cp.getConnection();

    System.out.println("--------可选课程的音讯-------");
    while(rs.next()) {

    PreparedStatement ps=conn.prepareStatement(sql);
    ps.setString(1, tnr.addressRegex());
    ResultSet rs=ps.executeQuery();
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

    couID = rs.getString("couID");
    couName = rs.getString("couName");
    couTeacher = rs.getString("couTeacher");

    ls.add(bc);
    }
    for(Person p1:ls)
    {
    System.out.println(p1);
    }
    if(!rs.next())
    {
    System.out.println("数据库未有有关材质");
    }
    rs.close();
    ps.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //修改钦点名字音讯
    public void modifyname(int id )
    {
    try {

    System.out.println(couID " " couName " " couTeacher);
    }

    Connection conn=cp.getConnection();
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="update person set name=?where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setString(1, tnr.nameRegex());
    ps.setInt(2, id);
    ps.executeUpdate();
    System.out.println("姓名修改成功");
    ps.close();
    conn.close();
    cp.close();

    System.out.println("n Please choose your course n");

    } catch (Exception e) {

    stat= conn.createStatement();

    System.out.println("姓名修改不成事");
    }
    }
    //修改钦命年龄音信
    public void modifyage(int id1 )
    {
    try {

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

    Connection conn=cp.getConnection();

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

    TelNoteRegex tnr=new TelNoteRegex();

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

    String sql="update person set age=?where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setInt(1, tnr.ageRegex());
    ps.setInt(2, id1);
    ps.executeUpdate();
    System.out.println("年龄修改成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {

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

    System.out.println("年龄修改不成事");
    }
    }
    //修改内定性别音讯
    public void modifysex(int id2 )
    {
    try {

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

    Connection conn=cp.getConnection();
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="update person set sex=?where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setString(1, tnr.sexRegex());
    ps.setInt(2, id2);
    ps.executeUpdate();
    System.out.println("性别修改成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    System.out.println("性别修改不成功");
    }
    }
    //修改钦定编号音讯
    public void modifytelnum(int id3 )
    {
    try {

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

    Connection conn=cp.getConnection();
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="update person set telnum=?where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setString(1, tnr.telNumRegex());
    ps.setInt(2, id3);
    ps.executeUpdate();
    System.out.println("电话号码修改成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    System.out.println("电话号码修改不成功");
    }
    }
    //修改内定地方消息
    public void modifyaddress(int id4 )
    {
    try {

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

    Connection conn=cp.getConnection();
    TelNoteRegex tnr=new TelNoteRegex();
    String sql="update person set address=?where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setString(1, tnr.addressRegex());
    ps.setInt(2, id4);
    ps.executeUpdate();
    System.out.println("地址修改成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    System.out.println("地址修改不成事");
    }
    }
    //删除钦赐客户音讯
    public void delete()
    {
    try {
    Connection conn=cp.getConnection();
    Scanner scc=new Scanner(System.in);
    System.out.println("输入须求删除的id");
    int id=scc.nextInt();
    String sql="delete person where id=?";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.setInt(1, id);
    ps.executeUpdate();
    System.out.println("删除成功");
    ps.close();
    conn.close();
    cp.close();
    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    System.out.println("删除不成事");
    }
    }
    //删除全体客户音讯
    public void deleteAll()
    {
    try {
    Connection conn=cp.getConnection();
    String sql="delete person ";
    PreparedStatement ps= conn.prepareStatement(sql);
    ps.executeUpdate();
    System.out.println("删除成功");
    ps.close();
    conn.close();
    cp.close();

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

    } catch (Exception e) {
    // TODO 自动生成的 catch 块
    System.out.println("删除不成事");
    }
    }
    //按顾客姓名排序音讯
    public List<Person> orderName()
    {
    try {
    Connection conn= cp.getConnection();
    Statement st=conn.createStatement();
    String sql="select * from person order by name ";
    ResultSet rs=st.executeQuery(sql);
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));

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

    ls.add(bc);
    }
    for(Person p:ls)
    {
    System.out.println(p);
    }

    System.out.println("nHere is your course that you have choosen");

    rs.close();
    st.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按客商年龄排序新闻
    public List<Person> orderAge()
    {
    try {
    Connection conn= cp.getConnection();
    Statement st=conn.createStatement();
    String sql="select * from person order by age ";
    ResultSet rs=st.executeQuery(sql);
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));
    ls.add(bc);
    }
    for(Person p:ls)
    {
    System.out.println(p);
    }
    rs.close();
    st.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }
    //按顾客性别排序音讯
    public List<Person> orderSex()
    {
    try {
    Connection conn= cp.getConnection();
    Statement st=conn.createStatement();
    String sql="select * from person order by sex ";
    ResultSet rs=st.executeQuery(sql);
    //遍历结果集
    while(rs.next())
    {
    Person bc=new Person();
    bc.setId(rs.getInt("id"));
    bc.setName(rs.getString("name"));
    bc.setAge(rs.getInt("age"));
    bc.setSex(rs.getString("sex"));
    bc.setTelnum(rs.getString("telnum"));
    bc.setAddress(rs.getString("address"));
    ls.add(bc);
    }
    for(Person p:ls)
    {
    System.out.println(p);
    }
    rs.close();
    st.close();
    conn.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }
    return ls;
    }

    Statement stat = null;
    ResultSet rs = null;

    }

    try {

    package com.hanqi.telbook;
    
    import java.util.List;
    
    public class App {
    
        public static void main(String[] args) {
            Menu me=new Menu();
            me.start();
    
    
    
    
        }
    
    }
    

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

     

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

    while(rs.next()) {

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

    if(stuID.equals(ID))

    System.out.println(stuID " " couID1 " " couID2 " " couID3 " " couID4 "n");

    }

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

    /*学员注册*/
    public static void StuRigistration() throws SQLException{

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

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

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

    StudentMenu1();

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

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

    System.out.println("n Here is student` information n");

    Statement stat = null;
    ResultSet rs = null;

    try {

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

    String stuID = null;
    String stuName = null;

    while(rs.next()) {

    stuID = rs.getString("stuID");
    stuName= rs.getString("stuName");

    System.out.println(stuID " " stuName "n");

    ManagerMenu1();
    }

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

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

    System.out.println("n Here is course`information n");

    Statement stat = null;
    ResultSet rs = null;

    try {

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

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

    while(rs.next()) {

    couID = rs.getString("couID");
    couName = rs.getString("couName");
    couTeacher = rs.getString("couTeacher");

    System.out.println(couID " " couName " " couTeacher "n");

    ManagerMenu1();
    }

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

    本文由新葡亰496net发布于网络数据库,转载请注明出处:新葡亰496net:增删改查,电话薄设计

    关键词: