欢迎来到天天文库
浏览记录
ID:9377667
大小:162.25 KB
页数:18页
时间:2018-04-29
《学生选课系统(连接mysql数据库)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/*JDBC连接数据库*/packageimmoc4.bao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassJDBC{privatestaticfinalStringURL="jdbc:mysql://localhost:3306/a?characterEncoding=utf8";privatestaticfinalStr
2、ingUSER="root";privatestaticfinalStringPASSWORD="995923";privatestaticConnectionconn=null;static{try{Class.forName("com.mysql.jdbc.Driver");conn=DriverManager.getConnection(URL,USER,PASSWORD);}catch(ClassNotFoundExceptione){e.printStackTrace();}catch(SQLExceptione){e.printStackTrace(
3、);}}publicstaticConnectiongetConnection(){returnconn;}}/*登录界面*/packageimmoc4.bao;importjava.awt.FlowLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.SQLException;importjava.util.Scanner;importjavax.swing.JButton;importjavax.swing.JFrame;impor
4、tjavax.swing.JLabel;importjavax.swing.JTextField;publicclassViewextendsJFrame{staticGongNenggn=newGongNeng();staticStudents=newStudent();staticJTextFieldtext1;staticJTextFieldtext2;staticJButtonbutton;publicvoiddenglu(){setLayout(newFlowLayout());add(newJLabel("用户id:"));text1=newJTex
5、tField(20);add(text1);add(newJLabel("密码:"));text2=newJTextField(20);add(text2);button=newJButton("登录");add(button);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口}publicstaticvoidmain(String[]args){Viewdl=newView();dl.setBounds(300,300,300,200);dl.setTitle("学生选
6、课管理系统");dl.denglu();button.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubdl.dispose();s.setStudent_id(Integer.parseInt(text1.getText()));s.setStudent_code(text2.getText());try{gn.correspond(s);}catch(SQLExceptione1){//TODO
7、Auto-generatedcatchblocke1.printStackTrace();}}});}}/*主界面*/packageimmoc4.bao;importjavax.swing.*;importimmoc4.bao.Course;importjava.awt.*;importjava.awt.event.*;importjava.sql.SQLException;publicclassCardextendsJFrame{/**JFrame的布局管理器是BorderLayout*/Courseg=newCourse();GongNenggn=newGo
8、ngNeng();JPa
此文档下载收益归作者所有