欢迎来到天天文库
浏览记录
ID:20450314
大小:61.12 KB
页数:5页
时间:2018-10-12
《java学生信息录入和查询(连接mysql数据库)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、1.成绩录入packagestudentManage;importimportimportimportimportimportimportimportjava•awt•GridLayout;java.awt.event.ActionEvent;java.awt.event.ActionListener;java•sql.Connection;java.sql.DniverManager;ava.sql,ResultSet;java•sql.SQLException;java.sql.Statement;importjavax.swing.*;OTextFieldDTextFieldDTe
2、xtFieldDTextFieldpublicclassStudentManageSystemextendsDFrame{jtfdID=new]TextField(8);jtfdName=new3TextField(128);jtfdSex=new3TextField(128);jtfdAge=new]TextField(8);publicStudentManageSystem(){JButtonjbtnEnter=new〕Button(”录入");JButtonjbtnClear=newZJButton("清零••);3LabeljlbllD=new〕Label("学号”);DLabe
3、ljlblName=new]Label("姓名••);]LabeljlblSex=new]Label("性别");OLabeljlblAge=new]Label("年龄");setLayout(newGridLayout(5,2,5,5));add(jlbllD);add(jtfdID);add(jlblName);add(jtfdName);add(jlblSex);add(jtfdSex);add(jlblAge);add(jtfdAge);add(jbtnEnter);add(jbtnClear);jbtnEnter>addActionListener(newEnterListen
4、er^));jbtnClear>addActionListener(newClearListener());}classEnterListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){Booleanrs=null;try{Class./or/Va/ne("com.mysql.jdbc.Driver");Connectionconn=DriverManager.getConnection("jdbc:mysql://127.0•0•1:3306/test?useUnicode=true&charac
5、terEncoding=utf8,,/,rootl,,/,root");Statementstmt=conn.createStatement();Stringsql="insertintostudentvalues(*"+jtfdID.getText()+"■/"+jtfdName.getText()+"1/n+jtfdSex.getText()+"'/"+jtfdAge•getText()+"•)";stmt.execute(sql);jtfdID.setText("M);jtfdName.setText("");jtfdSex.setTextC*jtfdAge.setText("")
6、;}catch(ClassNotFoundExceptione2){System.out.printlnC^orry^can'tfindtheDriver!");e2.printStackTrace();}catch(SQLExceptione3){e3.printStackTrace();}catch(Exceptione4){e4.printStackTrace();}}}classClearListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){jtfdID.setText(njtfdName
7、.setText("");jtfdSex.setTextC'");jtfdAge.setText(••");publicstaticvoidmain(String[]args){StudentManageSystems=newStudentManageSystem();s.setTitle("学生个人信息录入");s.setSize(400,300);s.setLocationRelativeTo(null);s.setDefaul
此文档下载收益归作者所有