学生选课系统(连接Mysql数据库)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*

JDBC连接数据库

*/

package immoc4.bao;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class JDBC {

private static final String URL = "jdbc:mysql://localhost:3306/a?characterEncoding=utf8";

private static final String USER = "root";

private static final String PASSWORD = "995923";

private static Connection conn = null;

static {

try {

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(URL, USER, PASSWORD);

} catch (ClassNotFoundException e) {

e.printStackTrace();

} catch (SQLException e) {

e.printStackTrace();

}

}

public static Connection getConnection() {

return conn;

}

}

/*

登录界面

*/

package immoc4.bao;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.SQLException;

import java.util.Scanner;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class View extends JFrame{

static GongNeng gn = new GongNeng();

static Student s = new Student();

static JTextField text1;

static JTextField text2;

static JButton button;

public void denglu(){

setLayout(new FlowLayout());

add(new JLabel("用户id:"));

text1 = new JTextField(20);

add(text1);

add(new JLabel("密码:"));

text2 = new JTextField(20);

add(text2);

button = new JButton("登录");

add(button);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口}

public static void main(String []args){

View dl = new View();

dl.setBounds(300, 300, 300, 200);

dl.setTitle("学生选课管理系统");

dl.denglu();

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

dl.dispose();

s.setStudent_id(Integer.parseInt(text1.getText()));

s.setStudent_code(text2.getText());

try {

gn.correspond(s);

} catch (SQLException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

});

}

}

/*

主界面

*/

package immoc4.bao;

import javax.swing.*;

import immoc4.bao.Course;

import java.awt.*;

import java.awt.event.*;

import java.sql.SQLException;

public class Card extends JFrame{

/*

* JFrame的布局管理器是BorderLayout

*/

Course g = new Course();

GongNeng gn = new GongNeng();

JPanel p;//位于中心区域的面板

JButton b1,b2,b3,b4;//位于北部区域的四个按钮

JButton add;

JButton delete;

JButton update;

JButton query;

JLabel add_id,add_name,add_teacher_name;

JLabel delete_id;

JLabel update_id,update_name,update_teacher_name;

JLabel query_id;

JLabel query_show;

相关文档
最新文档