⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataopera.java

📁 用java实现了一个学籍管理系统
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package stuinfomanage;import java.sql.*;import javax.swing.JOptionPane;/** * * @author Administrator */public class DataOpera {	public DataOpera() throws java.lang.ClassNotFoundException {		try {			Class.forName(drv);		} catch (java.lang.ClassNotFoundException e) {			throw e;		}	}    public void ConnectData() throws SQLException {        try {        connection = DriverManager.getConnection(dbURL, UserName, PassWord);        statement = connection.createStatement();        } catch (SQLException e) {        throw e;        }    }    public void ConnectClose() throws SQLException {        if (resultSet != null)            resultSet.close();        if (statement != null)            statement.close();        if (connection != null)            connection.close();	}    public void deleteAll()throws SQLException    {        ConnectData();        String cmd="delete from StuRec";        statement.execute(cmd);    }    public boolean RegisterOp(String name, String num,String sex,String compiler,String soft) throws SQLException {		boolean success = true;		try {			ConnectData();			success = statement				.execute("insert into StuRec values ('" + num					+ "','" + name+"','" +sex+"','"+compiler+"','"+soft+"')");			ConnectClose();		} catch (SQLException e) {			throw e;		}		return success;	}    public String QueryOp(String query, String n)			throws SQLException, Exception {        String show="";		try {			ConnectData();            String tmp="select * from StuRec where "+query+"='";			resultSet = statement					.executeQuery(tmp + n + "'");		/*	if (!resultSet.next()) {				throw new Exception("无该学生:" + n);			}*/      //      JOptionPane.showMessageDialog(null,"弹出对话框") ;		} catch (SQLException e) {			throw e;		}        while(resultSet.next())        {            for(int i=1;i<5;i++)                show=show+resultSet.getString(i)+"\t";            show=show+resultSet.getString(5)+"\n";        }        if(show=="")           JOptionPane.showMessageDialog(null,"没有满足查询条件的学生") ;        ConnectClose();		return show;	}    public ResultSet EditOp()throws SQLException    {        ResultSet rs=null;        ConnectData();        rs=statement.executeQuery("select * from StuRec");        return rs;    }    public ResultSet SortOp(String n)throws SQLException    {        ResultSet rs=null;        ConnectData();        String cmd="select 学号,姓名,"+n+" from StuRec order by "+n+" desc";        rs=statement.executeQuery(cmd);        return rs;    }    private Connection connection = null;	private Statement statement = null;	private ResultSet resultSet = null;    String drv="sun.jdbc.odbc.JdbcOdbcDriver";    String dbURL="jdbc:odbc:StuRec";    String UserName="";    String PassWord="";}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -