📄 dbhomework.java.bak
字号:
/* * DBHomework.java * * Created on 2006年1月13日, 下午9:34 *//** * * @author 超级用户 */import java.sql.*;import java.util.*;public class DBHomework extends javax.swing.JFrame { /** Creates new form DBHomework */ public DBHomework() { String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb"; try { Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); con = DriverManager.getConnection( url,"",""); } catch(Exception e) { System.out.println(e); } initComponents(); setBounds(100,100,570,330); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); getContentPane().setLayout(null); setTitle("\u738b\u98de09002135"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jButton1.setText("\u67e5\u8be21"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(10, 120, 80, 28); jButton2.setText("\u67e5\u8be22"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2); jButton2.setBounds(100, 120, 80, 28); jButton3.setText("\u67e5\u8be23"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); getContentPane().add(jButton3); jButton3.setBounds(190, 120, 80, 28); jButton4.setText("\u67e5\u8be24"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); getContentPane().add(jButton4); jButton4.setBounds(280, 120, 80, 28); jButton5.setText("\u67e5\u8be25"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); getContentPane().add(jButton5); jButton5.setBounds(370, 120, 80, 28); jButton6.setText("\u67e5\u8be26"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); getContentPane().add(jButton6); jButton6.setBounds(10, 160, 80, 28); jButton7.setText("\u67e5\u8be27"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); getContentPane().add(jButton7); jButton7.setBounds(100, 160, 80, 28); jButton8.setText("\u67e5\u8be28"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); getContentPane().add(jButton8); jButton8.setBounds(190, 160, 80, 28); jButton9.setText("\u67e5\u8be29"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); getContentPane().add(jButton9); jButton9.setBounds(280, 160, 80, 28); jButton10.setText("\u67e5\u8be210"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); getContentPane().add(jButton10); jButton10.setBounds(370, 160, 80, 28); jLabel1.setText("\u67e5\u8be2\u6761\u4ef6"); getContentPane().add(jLabel1); jLabel1.setBounds(10, 10, 60, 18); jTextField1.setFocusable(false); getContentPane().add(jTextField1); jTextField1.setBounds(10, 30, 440, 22); jLabel2.setText("SQL"); getContentPane().add(jLabel2); jLabel2.setBounds(10, 60, 26, 18); getContentPane().add(jTextField2); jTextField2.setBounds(10, 80, 440, 20); pack(); }//GEN-END:initComponents private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed //请在此处增加您的处理代码: //修改jTextField1,jTextField2的代码 jTextField1.setText("10:查询1984年~1986年出生的学生的姓名、总平均成绩及已修学分数"); jTextField2.setText("select sname ,avg(grade),sum(credit) from student,sc,course where (student.sno=sc.sno) and (course.cno=sc.cno) and (year(bdate) between 1984 and 1986) and (grade is not null) group by sname"); //生成Table窗口 Vector vec =new Vector(3); vec.addElement("姓名"); vec.addElement("总平均成绩"); vec.addElement("已修学分数"); try { stmt=con.createStatement(); rset=stmt.executeQuery("select sname ,avg(grade),sum(credit) from student,sc,course where (student.sno=sc.sno) and (course.cno=sc.cno) and (year(bdate) between 1984 and 1986) and (grade is not null) group by sname" ); t=new Table(rset,"查询10",vec); t.setVisible(true); } catch(Exception e ) {} }//GEN-LAST:event_jButton10ActionPerformed private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed //请在此处增加您的处理代码: //修改jTextField1,jTextField2的代码 jTextField1.setText("9:查询有一门以上(含一门)三学分以上的课程的成绩低于70分的学生的姓名"); jTextField2.setText("select sname from student where exists(select * from sc,course where student.sno=sc.sno and course.cno=sc.cno and credit>3 and grade is not null and grade<70)"); //生成Table窗口 Vector vec =new Vector(1); vec.addElement("姓名"); try { stmt=con.createStatement(); rset=stmt.executeQuery("select sname from student where exists(select * from sc,course where student.sno=sc.sno and course.cno=sc.cno and credit>3 and grade is not null and grade<70)" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -