当前位置:首页 > java学生选课系统(完整源代码,sql2005)
Connection Successful! } catch (Exception e) { e.printStackTrace(); } return dbConn; } }
Addstu.jaba: import java.awt.*; import javax.swing.*; import java.sql.*;
import java.awt.event.*;
public class Addstu extends JPanel implements ActionListener{ JTextField 学号,姓名,系别; JButton 录入; public Addstu(){ try
{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch(Exception e){System.err.println(\不能设置外观: 学号=new JTextField(12); 姓名=new JTextField(12); 系别=new JTextField(12); 录入=new JButton(\录入\ 录入.addActionListener(this); Box box1=Box.createHorizontalBox();//横放box Box box2=Box.createHorizontalBox(); Box box3=Box.createHorizontalBox(); Box box4=Box.createHorizontalBox(); box1.add(new JLabel(\学号:\ box1.add(学号); box2.add(new JLabel(\姓名:\ box2.add(姓名); box3.add(new JLabel(\系别:\
\ box3.add(系别); box4.add(录入); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); JPanel messPanel=new JPanel(); messPanel.add(boxH); setLayout(new BorderLayout()); add(messPanel,BorderLayout.CENTER); validate(); }
public void actionPerformed(ActionEvent c){ Object obj=c.getSource(); if(obj==录入){ if(学号.getText().equals(\姓名.getText().equals(\系别.getText().equals(\ JOptionPane.showMessageDialog(this,\学生信息请填满再录入!\ } Statement stmt=null; ResultSet rs1=null; String sql,sql1; sql1=\学号.getText()+\ sql=\into S values('\学号.getText()+\姓名.getText()+\系别.getText()+\ 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{ stmt.executeUpdate(sql); JOptionPane.showMessageDialog(this,\添加成功\ } rs1.close(); stmt.close(); } catch(SQLException e){
System.out.print(\Exception occur.Message is:\ } } }
//连接数据库方法
public static Connection CONN(){ String driverName = \ //加载JDBC驱动 String dbURL = \DatabaseName=student\ //连接服务器和数据库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; } }
DelC.java:
import java.awt.*;
import java.awt.event.*; import java.sql.*; import javax.swing.*;
public class DelC extends JPanel implements ActionListener{ String save=null; JTextField 课号1,课号,课名; JButton 删除,查找; public DelC(){ 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(课名); box4.add(删除); box5.add(new JLabel(\课号:\ box5.add(课号1); box5.add(查找); Box boxH=Box.createVerticalBox();//竖放box boxH.add(box1); boxH.add(box2); boxH.add(box3); boxH.add(box4); boxH.add(Box.createVerticalGlue()); 删除.addActionListener(this); 查找.addActionListener(this); JPanel picPanel=new JPanel(); JPanel messPanel=new JPanel(); messPanel.add(box5); picPanel.add(boxH); setLayout(new BorderLayout()); JSplitPane JSplitPane(JSplitPane.VERTICAL_SPLIT,messPanel,picPanel);//分割 add(splitV,BorderLayout.CENTER); validate(); }
public void actionPerformed(ActionEvent e){ Object obj=e.getSource();
splitV=new
共分享92篇相关文档