欢迎来到天天文库
浏览记录
ID:35478093
大小:76.12 KB
页数:11页
时间:2019-03-25
《java课程设计数据库操作》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、packagestudent;importjava.awt.*;importjava.awt.event.ActionEvent;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.Vector;importjavax.swing.JFrame;importjavax.sw
2、ing.JOptionPane;importjavax.swing-JPanel;importjavax.swing.JScrollPane;importjavax.swing.JTable;importjavax.swing.table.AbstractTableModel;publicclassSD{ResultSetrs;//定义返冋结果值Stringstrurl=,,jdbc:odbc:myDBH;//创建指定数据库的URLStringstrdriver=Msun.jdbc.odbcJdbcOdbcDriv
3、erH;//创建驱动程序publicConnectioncon=null;publicStatementst=null;〃查询方法,返冋查询结果集publicstaticvoidmain(String[]args){MainFramemainFrame=newMainFrame();mainFrame.setSize(500,500);//宽和高mainFrame.setVisible(true);mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}/
4、/endmainpublicResultSetgetResult(Stringsql){try{Class.forName(strdriver);con=DriverManage匚getConnection(stnjrl);st=con.createStatement();rs=st.executeQuery(sql);returnrs;}//endtrycatch(Exceptione){System.out.println(MgetResultH+e.toString());returnnull;)//endc
5、atch}//endgetResult〃执行更新、删除语句方法publicvoidexecuteSql(Stringsql){try{Class.forName(slrdriver);con=DriverManage匚getConnection(strurl);st=con.createStatement();st.executeUpdate(sql);con.commit();}//endtrycatch(Exceptione){System.out.println(MgetResultH+e.toStringO
6、);}//endcatch}//endexecuteSqlpublicvoidclose()throwsSQLException{if(con!=null)con.close();}//endclose}classMainFrameextendsJFrame{privateJPanelcontentPane;〃设置按纽privateButtonshowButton=newButton();privateButtonsearchButton=newButton();privateButtoninsertButton=
7、newButton();privateButtondeleteButton=newButton();privateButtonmodifyButton=newButton();〃设置标签privateLabelnumLabel=newLabel();privateLabelnameLabel=newLabel();privateLabelchineseLabel=newLabel();privateLabelmathLabel=newLabel();privateLabelenglishLabel=newLabel
8、();〃设置文本框privateTextFieldnumField=newTextField();privateTextFieldnameField=newTextField();privateTextFieldchineseField=newTextField();privateTextFieldmathField=newTextField();priva
此文档下载收益归作者所有