毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

JAVA学生管理系统 第8页

更新时间:2009-9-14:  来源:毕业论文
JAVA学生管理系统 第8页
import java.sql.*;

/**
 * 连接数据库的类
 */
public class Database {
 
 private Statement stmt=null;
 ResultSet rs=null;
 private Connection conn=null;
 String sql;
 String strurl="jdbc:odbc:scmanage";
 
 public Database(){
 }
 
 /**
  * 打开数据库连接
  */
 public void OpenConn()throws Exception{
  try{
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   conn=DriverManager.getConnection(strurl);
  }
  catch(Exception e){
   System.err.println("OpenConn:"+e.getMessage());
  }
 }

 /**
  * 执行sql语句,返回结果集rs
  */
 public ResultSet executeQuery(String sql){
  stmt = null;
  rs=null;
  try{
   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
   rs=stmt.executeQuery(sql);
  }
  catch(SQLException e){
   System.err.println("executeQuery:"+e.getMessage());
  }
  return rs;
 }

 /**
  * 执行sql语句
  */
 public void executeUpdate(String sql){
  stmt=null;
  rs=null;
  try{
   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
   stmt.executeQuery(sql);
   conn.commit();
  }
  catch(SQLException e){
   System.err.println("executeUpdate:"+e.getMessage());
  }
 }
 
 public void closeStmt(){
  try{
   stmt.close();
  }
  catch(SQLException e){
   System.err.println("closeStmt:"+e.getMessage());
  }
 }

 /**
  * 关闭数据库连接
  */
 public void closeConn(){
  try{
   conn.close();
  }
  catch(SQLException ex){
   System.err.println("aq.closeConn:"+ex.getMessage());
  }
 }
 
 /*
import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * 课程信息管理模块
 * 修改课程信息的类
 */
public class DelCourseInfo extends CourseInfo{
 String cNum_str = "";
 public DelCourseInfo() {
  this.setTitle("删除课程信息");
  this.setResizable(false);

  cNum.setEditable(false);
  cNum.setText("请查询课程号");
  cName.setEditable(false);
  cTeacher.setEditable(false);
  cType.setEditable(false);
  cTime.setEditable(false);
  cPlace.setEditable(false);

  //设置运行位置,使对话框居中
  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  this.setLocation( (int) (screenSize.width - 400) / 2 ,
      (int) (screenSize.height - 300) / 2 +45);
 }

 public void downInit(){
  searchInfo.setText("查询");
  searchInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(searchInfo);
  deleteInfo.setText("删除");
  deleteInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(deleteInfo);
  clearInfo.setText("清空");
  clearInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(clearInfo);
  eixtInfo.setText("退出");
  eixtInfo.setFont(new Font("Dialog",0,12));
  downPanel.add(eixtInfo);

  contentPane.add(downPanel,BorderLayout.SOUTH);

  searchInfo.setEnabled(true);
  deleteInfo.setEnabled(false);
  eixtInfo.setEnabled(true);

  //添加事件侦听
  searchInfo.addActionListener(this);
  deleteInfo.addActionListener(this);
  eixtInfo.addActionListener(this);
 }
 /**
  * 事件处理
  */
 public void actionPerformed(ActionEvent e) {
  Object obj = e.getSource();
  String[] s = new String[5];

  if (obj == eixtInfo) { //退出
   this.dispose();
  }
  else if (obj == deleteInfo) { //删除
   int ifdel = JOptionPane.showConfirmDialog(null,"真的要删除该信息?","提示信息",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE );
   if(ifdel == JOptionPane.YES_OPTION){
    CrsBean delCrs = new CrsBean();
    delCrs.crsDel(cNum.getText());
    
    this.dispose();

    DelCourseInfo dci = new DelCourseInfo();
    dci.downInit();
    dci.pack();
    dci.setVisible(true);
   }
   else{
    return;
   }
  }
  else if (obj == searchInfo) { //学号查询
   CourseInfoSearchCnum cisc = new CourseInfoSearchCnum(this);
   cisc.pack();
   cisc.setVisible(true);
   cNum_str = cisc.getCnum();

   CrsBean searchCrs = new CrsBean();
   s = searchCrs.crsSearch(cNum_str);
   if(s == null){
    JOptionPane.showMessageDialog(null, "记录不存在!");
    cNum.setText("请查询学号");
    cName.setText("");
    cTeacher.setText("");
    cPlace.setText("");
    cType.setText("");
    cTime.setText("");
        
    cName.setEditable(false);
    cTeacher.setEditable(false);
    cPlace.setEditable(false);
    cType.setEditable(false);
    cTime.setEditable(false);
    deleteInfo.setEnabled(false);
    return;
   }
   else{
    cNum.setText(cNum_str);
    cName.setText(s[0]);
    cTeacher.setText(s[1]);
    cPlace.setText(s[2]);
    cType.setText(s[3]);
    cTime.setText(s[4]);

    cName.setEditable(true);
    cTeacher.setEditable(true);
    cPlace.setEditable(true);
    cType.setEditable(true);
    cTime.setEditable(true);
    deleteInfo.setEnabled(true);   }  } }

上一页  [1] [2] [3] [4] [5] [6] [7] [8] 

JAVA学生管理系统 第8页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。