0 Replies Latest reply: Nov 14, 2008 4:19 AM by 843810 RSS

    How can I Save information each 60 seconds in SQL server 2005 using a timer

    843810
      Hi everyone,

      I have a problem with the following project. I'm going to make an application where you can insert customer information. The application is finished but I have 1 problem. The information must be saved each 60 seconds in the sql server 2005 using a timer. This is a project from school and I really need help for this.
      Here is my source:

      productie.java*

      package untitled12;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.sql.*;
      public class productie extends JFrame {
      JPanel contentPane;
      BorderLayout borderLayout1 = new BorderLayout();

      //Tekstveld declareren
      JTextField tekstveld1 = new JTextField("");
      JTextField tekstveld2 = new JTextField("");
      JTextField tekstveld3 = new JTextField("");
      JTextField tekstveld4 = new JTextField("");
      JTextField tekstveld5 = new JTextField("");
      JTextField tekstveld6 = new JTextField("");
      JTextField tekstveld7 = new JTextField("");

      //Buttons Declareren
      JButton knop1 = new JButton("Start");
      JButton knop2 = new JButton("Stop");

      //Labels Declareren
      JLabel jLabel1 = new JLabel();
      JLabel jLabel2 = new JLabel();
      JLabel jLabel3 = new JLabel();
      JLabel jLabel4 = new JLabel();
      JLabel jLabel5 = new JLabel();
      JLabel jLabel6 = new JLabel();
      JLabel jLabel7 = new JLabel();


      //Construct the frame
      public productie()
      {
      enableEvents(AWTEvent.WINDOW_EVENT_MASK);
      try
      {
      jbInit();
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }
      }
      //Component initialization
      private void jbInit() throws Exception
      {
      //Layout bepalen
      contentPane = (JPanel) this.getContentPane();
      contentPane.setLayout(null);
      this.setForeground(Color.gray);
      this.setSize(new Dimension(768, 409));
      this.setTitle("Productie Toetsenbord");
      //Labels Visueel maken
      jLabel1.setText("Plastic");
      jLabel1.setBounds(new Rectangle(80, 50, 150, 20));
      tekstveld1.setText("0,10");
      tekstveld2.setText("0,20");
      tekstveld3.setText("0,1");
      tekstveld4.setText("0,1");
      tekstveld5.setText("0,10");
      tekstveld6.setText("1,00");
      tekstveld7.setText("1");
      contentPane.add(jLabel1,null);
      jLabel2.setText("Metaal");
      jLabel2.setBounds(new Rectangle(80, 80, 150, 20));
      contentPane.add(jLabel2, null);
      jLabel3.setText("Toetsen");
      jLabel3.setBounds(new Rectangle(80, 105, 150, 30));
      contentPane.add(jLabel3, null);
      jLabel4.setText("Borden");
      jLabel4.setBounds(new Rectangle(80, 135, 150, 30));
      contentPane.add(jLabel4, null);
      jLabel5.setText("Arbeid");
      jLabel5.setBounds(new Rectangle(80, 165, 150, 30));
      contentPane.add(jLabel5, null);
      jLabel6.setText("Verkoopprijs");
      jLabel6.setBounds(new Rectangle(80, 195, 150, 30));
      contentPane.add(jLabel6, null);
      jLabel7.setText("Aantal");
      jLabel7.setBounds(new Rectangle(80, 225, 150, 30));
      contentPane.add(jLabel7, null);


      //Knoppen visueel maken
      knop1.addActionListener(new Knop1Handler());
      knop1.setBounds(80, 300, 130, 30);
      contentPane.add(knop1);
      knop2.addActionListener(new Knop2Handler());
      knop2.setBounds(220, 300, 130, 30);
      contentPane.add(knop2);

      //Tekstvelden visueel maken
      contentPane.add(tekstveld1);
      tekstveld1.setBounds(200, 50, 150, 20);
      contentPane.add(tekstveld2);
      tekstveld2.setBounds(200, 80, 150, 20);
      contentPane.add(tekstveld3);
      tekstveld3.setBounds(200, 110, 150, 20);
      contentPane.add(tekstveld4);
      tekstveld4.setBounds(200, 140, 150, 20);
      contentPane.add(tekstveld5);
      tekstveld5.setBounds(200, 170, 150, 20);
      contentPane.add(tekstveld6);
      tekstveld6.setBounds(200, 200, 150, 20);
      contentPane.add(tekstveld7);
      tekstveld7.setBounds(200, 230, 150, 20);

      }
      class Knop1Handler implements ActionListener
      {
      public void actionPerformed(ActionEvent g)
      {
      //Strings declareren
      String Plastic = tekstveld1.getText();
      String Metaal = tekstveld2.getText();
      String Toetsen = tekstveld3.getText();
      String Borden = tekstveld4.getText();
      String Arbeid = tekstveld5.getText();
      String Verkoopprijs = tekstveld6.getText();
      String Aantal = tekstveld7.getText();


      try {
      Statement stmt;
      //Hier haalt hij de driver op
      Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

      String connectionUrl = "jdbc:sqlserver://localhost;database=Zemmez;intergratedSecurity=false;username=sa;password=admin";
      Connection con = DriverManager.getConnection(connectionUrl);
      stmt = con.createStatement();
      stmt.executeUpdate("INSERT INTO Polisgegevens(Plastic, Metaal, Toetsen, Borden, Arbeid, Verkoopprijs, Aantal) VALUES('"+Plastic+"','"+Metaal+"','"+Toetsen+"','"+Borden+"','"+Arbeid+"','"+Verkoopprijs+"','"+Aantal+"')");
      //Connectie Sluiten
      con.close();
      }catch( Exception f )
      {
      f.printStackTrace();
      }
      //Terug naar het hoofdscherm
      Hoofdscherm frame2 = new Hoofdscherm();
      Dimension d = frame2.getToolkit().getScreenSize();
      frame2.setSize(250,150);
      frame2.setLocation(d.width/2-400 , d.height/2-300);
      frame2.setVisible(true);
      dispose();
      }
      }
      class Knop2Handler implements ActionListener
      {
      public void actionPerformed(ActionEvent g)
      {
      Hoofdscherm frame2 = new Hoofdscherm();
      Dimension d = frame2.getToolkit().getScreenSize();
      frame2.setSize(250,150);
      frame2.setLocation(d.width/2-400 , d.height/2-300);
      frame2.setVisible(true);
      dispose();
      }
      }
      }




      Application 1*


      package untitled12;
      import javax.swing.UIManager;
      import java.awt.*;
      import java.sql.*;
      public class Application1
      {
      public static void main(String args[])
      {
      {   //Hoofdscherm Oproepen
      Hoofdscherm frame1 = new Hoofdscherm();
      Dimension d = frame1.getToolkit().getScreenSize();
      frame1.setSize(250,150);
      frame1.setLocation(d.width/2-400 , d.height/2-300);
      frame1.setVisible(true);
      }

      }
      }