当前位置:首页 > java学生选课系统(完整源代码,sql2005)
try{ Connection dbConn1=CONN(); stmt=(Statement)dbConn1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); rs1=stmt.executeQuery(sql1); if(rs1.next()){ JOptionPane.showMessageDialog(this,\已存在此学号学生\ } else{ sqlSC=\学号.getText()+\ stmt.executeUpdate(sql); stmt.executeUpdate(sqlSC); save=null; JOptionPane.showMessageDialog(null,\修改完成\ 学号.setText(\ 姓名.setText(\ 系别.setText(\ stmt.close(); rs1.close(); }catch(SQLException e1){ System.out.print(\ } } }}}} }
//连接数据库方法
public static Connection CONN(){ String driverName = \ //加载JDBC驱动 String dbURL = \ //连接服务器和数据库test String userName = \ //默认用户名 String userPwd = \ //密码 Connection dbConn=null; try { Class.forName(driverName); dbConn = DriverManager.getConnection(dbURL, userName, userPwd); System.out.println(\Successful!\ //如果连接成功 控制台输出Connection Successful! } catch (Exception e) {
e.printStackTrace(); } return dbConn; } }
UpdateC.java
import java.awt.*;
import java.awt.event.*; import java.sql.*; import javax.swing.*;
public class UpdateC extends JPanel implements ActionListener{ String save=null; JTextField 课号1,课号,课名; JButton 修改,查找;
public UpdateC(){ try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: \ 课号1=new JTextField(12); 课号=new JTextField(12); 课名=new JTextField(12); 修改=new JButton(\修改\ 查找=new JButton(\查找\ Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box3=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); Box box5=Box.createHorizontalBox(); box1.add(new JLabel(\课号:\ box1.add(课号); box2.add(new JLabel(\课名:\ box2.add(课名); box3.add(修改); box5.add(new JLabel(\课号:\ box5.add(课号1); box5.add(查找); 修改.addActionListener(this); 查找.addActionListener(this);
共分享92篇相关文档