永发信息网

做一个班级管理系统的java程序,怎么写代码

答案:1  悬赏:0  手机版
解决时间 2021-08-22 04:13
  • 提问者网友:骑士
  • 2021-08-21 17:06
要全部代码
最佳答案
  • 五星知识达人网友:北城痞子
  • 2021-08-21 18:43

package pack;
import java.sql.*;
import java.util.*;


public class DataBaseOperation {


    private static Connection conn;
    public void ins(Student[] students){    for(int i=0; i<students.length; i++)    ins(students[i]);
    }    void  ins(Student student){    String sql = "insert into student values(";    sql += "'" + student.getName() + "',";    sql += student.getAge() + ",'";    sql += student.getNum() + "','";    sql += student.getSex() + "')";


    connect();    try{    Statement stmt = conn.createStatement();    stmt.executeUpdate(sql);    }catch(SQLException e){}    close();
    }
      void  del(String name){    String sql = "delete from student where Name=" ;    sql+="'"+name+"'";


    connect();    try{    Statement stmt = conn.createStatement();    stmt.executeUpdate(sql);    }catch(SQLException e){}    close();
    }


    public Student[] getStudent(){    ArrayList list = new ArrayList();    String sql = "select * from student";    connect();    try{    Statement stmt = conn.createStatement();    ResultSet rst = stmt.executeQuery(sql);    while(rst.next()){    String name = rst.getString(1);    int age = rst.getInt(2);    int number = rst.getInt(3);    String sex= rst.getString(4);    Student p = new Student(name);    p.setAge(age);p.SetNum(number);    p.setSex(sex);    list.add(p);    }    rst.close();    }catch(SQLException e){}    return (Student[])list.toArray(new Student[0]);
    }


    public static void connect(){    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";    String url = "jdbc:odbc:xiao";    try{    Class.forName(driverName);    conn = DriverManager.getConnection(url);    }catch(ClassNotFoundException e){e.getMessage();    }catch(SQLException e){    e.getMessage();    }
    }
    private void close(){    try{    if(conn!=null) conn.close();    }catch(SQLException e){e.getMessage();}
    }


}


还要不?

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯