文档详情

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

发布:2017-12-17约1.29万字共18页下载文档
文本预览下载声明
/*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 blocke1.printStackTrace();} } }); }} /*主界面*/package immoc4.bao;import javax.swing.*;import immoc4.bao.Course;import java.awt.*;import jav
显示全部
相似文档