Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.25 KB | None | 0 0
  1.  
  2. import java.sql.*;
  3.  
  4. /*
  5.  * To change this license header, choose License Headers in Project Properties.
  6.  * To change this template file, choose Tools | Templates
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. /**
  11.  *
  12.  * @author Mathis
  13.  */
  14. public class Fahrradverleih extends javax.swing.JFrame {
  15.  
  16.     /**
  17.      * Creates new form Fahrradverleih
  18.      */
  19.     public Fahrradverleih() {
  20.         initComponents();
  21.     }
  22.  
  23.     /**
  24.      * This method is called from within the constructor to initialize the form.
  25.      * WARNING: Do NOT modify this code. The content of this method is always
  26.      * regenerated by the Form Editor.
  27.      */
  28.     @SuppressWarnings("unchecked")
  29.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  30.     private void initComponents() {
  31.  
  32.         jScrollPane1 = new javax.swing.JScrollPane();
  33.         taAusgabe2 = new javax.swing.JTextArea();
  34.         bKundeFT = new javax.swing.JButton();
  35.         jScrollPane2 = new javax.swing.JScrollPane();
  36.         taAusgabe1 = new javax.swing.JTextArea();
  37.         bKunden = new javax.swing.JButton();
  38.         bTT = new javax.swing.JButton();
  39.  
  40.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  41.  
  42.         taAusgabe2.setColumns(20);
  43.         taAusgabe2.setRows(5);
  44.         jScrollPane1.setViewportView(taAusgabe2);
  45.  
  46.         bKundeFT.setText("Kunde -> Fahrrad + Termin");
  47.         bKundeFT.addActionListener(new java.awt.event.ActionListener() {
  48.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  49.                 bKundeFTActionPerformed(evt);
  50.             }
  51.         });
  52.  
  53.         taAusgabe1.setColumns(20);
  54.         taAusgabe1.setRows(5);
  55.         jScrollPane2.setViewportView(taAusgabe1);
  56.  
  57.         bKunden.setText("Kunden");
  58.         bKunden.addActionListener(new java.awt.event.ActionListener() {
  59.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  60.                 bKundenActionPerformed(evt);
  61.             }
  62.         });
  63.  
  64.         bTT.setText("Tourteilnehmer + Termin");
  65.         bTT.addActionListener(new java.awt.event.ActionListener() {
  66.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  67.                 bTTActionPerformed(evt);
  68.             }
  69.         });
  70.  
  71.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  72.         getContentPane().setLayout(layout);
  73.         layout.setHorizontalGroup(
  74.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  75.             .addGroup(layout.createSequentialGroup()
  76.                 .addContainerGap()
  77.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  78.                     .addGroup(layout.createSequentialGroup()
  79.                         .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  80.                         .addGap(26, 26, 26)
  81.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
  82.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  83.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  84.                             .addComponent(bKundeFT, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
  85.                             .addComponent(bTT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  86.                     .addComponent(bKunden, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
  87.                 .addContainerGap(92, Short.MAX_VALUE))
  88.         );
  89.         layout.setVerticalGroup(
  90.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  91.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  92.                 .addComponent(bKunden)
  93.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  94.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  95.                     .addGroup(layout.createSequentialGroup()
  96.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97.                             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE)
  98.                             .addComponent(jScrollPane1))
  99.                         .addGap(19, 19, 19))
  100.                     .addGroup(layout.createSequentialGroup()
  101.                         .addComponent(bKundeFT)
  102.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  103.                         .addComponent(bTT)
  104.                         .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  105.         );
  106.  
  107.         pack();
  108.     }// </editor-fold>                        
  109.  
  110.     private void bKundeFTActionPerformed(java.awt.event.ActionEvent evt) {                                        
  111.     try {
  112.             Connection con = DriverManager.getConnection("jdbc:derby:F:\\Q1\\Info\\Q3\\Db_Beziehungen\\Db_Beziehungen");
  113.             Statement stmt = con.createStatement();
  114.             ResultSet rs = stmt.executeQuery("SELECT * FROM Verleih");
  115.             taAusgabe2.setText("");
  116.             while (rs.next()) {
  117.                 taAusgabe2.append(rs.getString("Verleihnummer") + "\t" + rs.getString("Kundennummer") + "\t" + rs.getString("Fahrradnummer") + "\t" + rs.getString("Termin"));
  118.                 taAusgabe2.append("\n");
  119.             }
  120.            
  121.             con.close();
  122.         } catch (SQLException e) {
  123.             e.printStackTrace();
  124.         }        // TODO add your handling code here:
  125.     }                                        
  126.  
  127.     private void bKundenActionPerformed(java.awt.event.ActionEvent evt) {                                        
  128.     try {
  129.             Connection con = DriverManager.getConnection("jdbc:derby:F:\\Q1\\Info\\Q3\\Db_Beziehungen\\Db_Beziehungen");
  130.             Statement stmt = con.createStatement();
  131.             ResultSet rs = stmt.executeQuery("SELECT * FROM Kunde");
  132.             taAusgabe1.setText("");
  133.             while (rs.next()) {
  134.                 taAusgabe1.append(rs.getString("Kundennummer") + "\t" + rs.getString("Name") + "\t" + rs.getString("Vorname"));
  135.                 taAusgabe1.append("\n");
  136.             }
  137.            
  138.             con.close();
  139.         } catch (SQLException e) {
  140.             e.printStackTrace();
  141.         }       // TODO add your handling code here:
  142.     }                                      
  143.  
  144.     private void bTTActionPerformed(java.awt.event.ActionEvent evt) {                                    
  145.     try {
  146.             Connection con = DriverManager.getConnection("jdbc:derby:F:\\Q1\\Info\\Q3\\Db_Beziehungen\\Db_Beziehungen");
  147.             Statement stmt = con.createStatement();
  148.            
  149.             int i = 0;
  150.             ResultSet rs = stmt.executeQuery("SELECT * FROM Belegung WHERE Tournummer = 'T1'");
  151.             while (rs.next()) {
  152.                 i=i++;
  153.             }
  154.             stmt.executeUpdate("UPDATE Tour SET Teilnehmerzahl = '"+i+"' WHERE Tournummer = 'T1'");
  155.             i=0;
  156.            
  157.             rs = stmt.executeQuery("SELECT * FROM Belegung WHERE Tournummer = 'T2'");
  158.             while (rs.next()) {
  159.                 i=i++;
  160.             }
  161.             stmt.executeUpdate("UPDATE Tour SET Teilnehmerzahl = '"+i+"' WHERE Tournummer = 'T2'");
  162.            
  163.            
  164.            
  165.             rs = stmt.executeQuery("SELECT * FROM Tour");
  166.             while (rs.next()) {
  167.                 taAusgabe2.append(rs.getString("Tournummer") + "\t" + rs.getString("Tourtermin") + "\t" + rs.getString("Länge") + "\t" + rs.getString("Teilnehmerzahl"));
  168.                 taAusgabe2.append("\n");
  169.             }
  170.            
  171.             con.close();
  172.         } catch (SQLException e) {
  173.             e.printStackTrace();
  174.         }       // TODO add your handling code here:
  175.     }                                  
  176.  
  177.     /**
  178.      * @param args the command line arguments
  179.      */
  180.     public static void main(String args[]) {
  181.         /* Set the Nimbus look and feel */
  182.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  183.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  184.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  185.          */
  186.         try {
  187.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  188.                 if ("Nimbus".equals(info.getName())) {
  189.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  190.                     break;
  191.                 }
  192.             }
  193.         } catch (ClassNotFoundException ex) {
  194.             java.util.logging.Logger.getLogger(Fahrradverleih.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  195.         } catch (InstantiationException ex) {
  196.             java.util.logging.Logger.getLogger(Fahrradverleih.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  197.         } catch (IllegalAccessException ex) {
  198.             java.util.logging.Logger.getLogger(Fahrradverleih.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  199.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  200.             java.util.logging.Logger.getLogger(Fahrradverleih.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  201.         }
  202.         //</editor-fold>
  203.  
  204.         /* Create and display the form */
  205.         java.awt.EventQueue.invokeLater(new Runnable() {
  206.             public void run() {
  207.                 new Fahrradverleih().setVisible(true);
  208.             }
  209.         });
  210.     }
  211.  
  212.     // Variables declaration - do not modify                    
  213.     private javax.swing.JButton bKundeFT;
  214.     private javax.swing.JButton bKunden;
  215.     private javax.swing.JButton bTT;
  216.     private javax.swing.JScrollPane jScrollPane1;
  217.     private javax.swing.JScrollPane jScrollPane2;
  218.     private javax.swing.JTextArea taAusgabe1;
  219.     private javax.swing.JTextArea taAusgabe2;
  220.     // End of variables declaration                  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement