Forum Stats

  • 3,781,422 Users
  • 2,254,516 Discussions
  • 7,879,688 Comments

Discussions

MySQL database records with Java Applets

2951827
2951827 Member Posts: 1
edited May 18, 2015 7:49PM in Java Applet Development

I have a system that sends the temperature data wireless. The system sends data to a device. The device IP address 10.90.11.155. I can see the current temperature data connected with this rope. But I want to find myself a way to store the archive data.

I will do with the data system helps you to register for a MySQL database.


ip adress : 10.90.11.155

port : 2000


"Html file"

<html><head><title>READINGS</title></head><body><center><table><tr valign=center><td><font face="Arial Black" size=5>zSeries</font></td></tr></table></center><br><br><br><center><h2>Group B</h2><applet code="read.class" width=800 height=380><param name=ZBgrp value="B"></applet></center><p><center><p><a href="/login?PW=12345678">Main Menu</a>


"read.class file"


import java.applet.Applet;

import java.awt.*;

import java.io.*;

import java.net.*;

import java.util.Date;

import java.util.StringTokenizer;

import javax.swing.JDialog;

import javax.swing.JFileChooser;

public class read extends Applet

    implements Runnable

{

    public read()

    {

        a_java_io_File_fld = null;

        a_java_awt_Button_fld = new Button("Data Logging: INACTIVE");

        a_long_fld = 0L;

        a_java_awt_Label_array1d_fld = new Label[8];

        b_java_awt_Label_array1d_fld = new Label[8];

        c_java_awt_Label_array1d_fld = new Label[8];

        a_java_awt_Label_array2d_fld = new Label[8][4];

        b_java_awt_Label_array2d_fld = new Label[8][4];

        a_java_awt_Label_fld = new Label("Name");

        b_java_awt_Label_fld = new Label("ID");

        c_java_awt_Label_fld = new Label("Sequence");

        a_java_awt_TextField_fld = new TextField();

        d_java_awt_Label_fld = new Label("seconds", 1);

        e_java_awt_Label_fld = new Label("Refresh", 1);

        a_java_lang_String_array1d_fld = new String[8];

        a_int_array1d_fld = new int[8];

        b_int_fld = 1;

        c_int_fld = 5;

        d_int_fld = 0;

        e_int_fld = 0;

        a_java_lang_Thread_fld = null;

        a_java_net_Socket_fld = null;

        b_java_io_PrintWriter_fld = null;

        a_java_io_BufferedInputStream_fld = null;

    }

    public void init()

    {

        setLayout(null);

        setBackground(Color.white);

        setSize(800, 380);

        a_java_awt_Label_fld.setAlignment(1);

        a_java_awt_Label_fld.setFont(new Font("Dialog", 0, 13));

        a_java_awt_Label_fld.setBounds(15, 10, 67, 20);

        add(a_java_awt_Label_fld);

        b_java_awt_Label_fld.setAlignment(1);

        b_java_awt_Label_fld.setFont(new Font("Dialog", 0, 13));

        b_java_awt_Label_fld.setBounds(100, 10, 33, 20);

        add(b_java_awt_Label_fld);

        c_java_awt_Label_fld.setAlignment(1);

        c_java_awt_Label_fld.setFont(new Font("Dialog", 0, 13));

        c_java_awt_Label_fld.setBounds(145, 10, 67, 20);

        add(c_java_awt_Label_fld);

        for(int i = 0; i < 8; i++)

        {

            a_java_awt_Label_array1d_fld[i] = new Label();

            a_java_awt_Label_array1d_fld[i].setText("--");

            a_java_awt_Label_array1d_fld[i].setAlignment(1);

            a_java_awt_Label_array1d_fld[i].setFont(new Font("Dialog", 1, 13));

            a_java_awt_Label_array1d_fld[i].setBounds(10, 40 + i * 30, 80, 20);

            add(a_java_awt_Label_array1d_fld[i]);

            b_java_awt_Label_array1d_fld[i] = new Label();

            b_java_awt_Label_array1d_fld[i].setText("-");

            b_java_awt_Label_array1d_fld[i].setAlignment(1);

            b_java_awt_Label_array1d_fld[i].setForeground(Color.black);

            b_java_awt_Label_array1d_fld[i].setFont(new Font("Dialog", 1, 13));

            b_java_awt_Label_array1d_fld[i].setBounds(100, 40 + i * 30, 33, 20);

            add(b_java_awt_Label_array1d_fld[i]);

            c_java_awt_Label_array1d_fld[i] = new Label();

            c_java_awt_Label_array1d_fld[i].setText("-");

            c_java_awt_Label_array1d_fld[i].setAlignment(1);

            c_java_awt_Label_array1d_fld[i].setForeground(Color.black);

            c_java_awt_Label_array1d_fld[i].setFont(new Font("Dialog", 1, 13));

            c_java_awt_Label_array1d_fld[i].setBounds(140, 40 + i * 30, 80, 20);

            add(c_java_awt_Label_array1d_fld[i]);

            for(int j = 0; j < 4; j++)

            {

                a_java_awt_Label_array2d_fld[i][j] = new Label();

                a_java_awt_Label_array2d_fld[i][j].setText("--");

                a_java_awt_Label_array2d_fld[i][j].setAlignment(1);

                a_java_awt_Label_array2d_fld[i][j].setBackground(new Color(176, 196, 222));

                a_java_awt_Label_array2d_fld[i][j].setForeground(Color.white);

                a_java_awt_Label_array2d_fld[i][j].setFont(new Font("Dialog", 1, 20));

                a_java_awt_Label_array2d_fld[i][j].setBounds(230 + j * 130, 40 + i * 30, 87, 20);

                add(a_java_awt_Label_array2d_fld[i][j]);

                b_java_awt_Label_array2d_fld[i][j] = new Label();

                b_java_awt_Label_array2d_fld[i][j].setText("--");

                b_java_awt_Label_array2d_fld[i][j].setFont(new Font("Dialog", 1, 12));

                b_java_awt_Label_array2d_fld[i][j].setBounds(320 + j * 130, 40 + i * 30, 40, 20);

                add(b_java_awt_Label_array2d_fld[i][j]);

            }

            a_java_lang_String_array1d_fld[i] = new String("--");

            a_int_array1d_fld[i] = 0;

        }

        add(a_java_awt_Button_fld);

        a_java_awt_Button_fld.setFont(new Font("Dialog", 1, 10));

        a_java_awt_Button_fld.setBackground(Color.lightGray);

        a_java_awt_Button_fld.setBounds(300, 310, 140, 25);

        add(e_java_awt_Label_fld);

        e_java_awt_Label_fld.setForeground(Color.black);

        e_java_awt_Label_fld.setFont(new Font("Dialog", 1, 10));

        e_java_awt_Label_fld.setBounds(300, 345, 40, 20);

        a_java_awt_TextField_fld.setText(Integer.toString(c_int_fld));

        add(a_java_awt_TextField_fld);

        a_java_awt_TextField_fld.setForeground(Color.black);

        a_java_awt_TextField_fld.setFont(new Font("Dialog", 1, 10));

        a_java_awt_TextField_fld.setBounds(346, 345, 38, 20);

        add(d_java_awt_Label_fld);

        d_java_awt_Label_fld.setForeground(Color.black);

        d_java_awt_Label_fld.setFont(new Font("Dialog", 1, 10));

        d_java_awt_Label_fld.setBounds(390, 345, 48, 20);

        a_boolean_fld = false;

        a_long_fld = 0L;

        c_int_fld = 5;

        d_int_fld = 0;

    }

    public void start()

    {

        a_int_fld = getParameter("ZBgrp").charAt(0) - 65 << 3;

        for(int i = 0; i < 8; i++)

            b_java_awt_Label_array1d_fld[i].setText(Integer.toString(a_int_fld + i));

        if((a_int_fld >> 3) + 1 >= 10)

            a_java_lang_String_fld = "0" + Integer.toString(((a_int_fld >> 3) + 1) / 10) + "0";

        else

            a_java_lang_String_fld = "00" + (char)((a_int_fld >> 3) + 65);

        if(a_java_lang_Thread_fld == null)

        {

            a_java_lang_Thread_fld = new Thread(this);

            a_java_lang_Thread_fld.start();

        }

    }

    public void stop()

    {

        if(a_java_lang_Thread_fld != null)

            a_java_lang_Thread_fld = null;

        if(a_java_net_Socket_fld != null)

            try

            {

                a_java_net_Socket_fld.close();

                return;

            }

            catch(Exception exception)

            {

                System.err.println("R" + a_int_fld + ": Error Closing Socket: " + exception);

            }

    }

    public void run()

    {

        do

        {

            if(a_java_lang_Thread_fld == null)

                break;

            if(a_java_net_Socket_fld == null)

                try

                {

                    a_java_net_Socket_fld = new Socket(getCodeBase().getHost(), 1001);

                    b_java_io_PrintWriter_fld = new PrintWriter(a_java_net_Socket_fld.getOutputStream(), true);

                    a_java_io_BufferedInputStream_fld = new BufferedInputStream(a_java_net_Socket_fld.getInputStream());

                }

                catch(UnknownHostException _ex)

                {

                    System.err.println("R" + a_int_fld + ": Don't know about host: iServer.");

                    continue;

                }

                catch(IOException ioexception)

                {

                    System.err.println("R" + a_int_fld + ": Couldn't get connection - " + ioexception);

                    continue;

                }

            int i = 0;

            String s = new String("?");

            try

            {

                e_int_fld = 0;

                do

                {

                    if(e_int_fld >= 30)

                        break;

                    if(e_int_fld % 5 == 0)

                        if(b_int_fld == 1)

                            b_java_io_PrintWriter_fld.println("EQNG" + a_java_lang_String_fld);

                        else

                            b_java_io_PrintWriter_fld.println("ERDG" + a_java_lang_String_fld);

                    try

                    {

                        Thread.sleep(1000L);

                    }

                    catch(InterruptedException _ex) { }

                    byte abyte0[] = new byte[4096];

                    int i1 = 0;

                    if((i1 = a_java_io_BufferedInputStream_fld.available()) > 0)

                    {

                        if(a_java_io_BufferedInputStream_fld.read(abyte0, 0, i1) != 0)

                        {

                            if(abyte0[0] != 79 && abyte0[0] != 69 && abyte0[0] != 87 && abyte0[0] != 84)

                            {

                                s = new String(abyte0, 0, i1);

                                StringTokenizer stringtokenizer = new StringTokenizer(s, "");

                                if(a_boolean_fld && b_int_fld == 0)

                                    a_java_io_PrintWriter_fld.print(new Date() + ",");

label0:

                                do

                                {

                                    int k1;

                                    int l1;

                                    String as[];

label1:

                                    do

                                        do

                                        {

                                            String s1;

                                            do

                                            {

                                                if(!stringtokenizer.hasMoreTokens())

                                                    break label0;

                                                s1 = stringtokenizer.nextToken();

                                                StringTokenizer stringtokenizer1 = new StringTokenizer(s1, " ");

                                                k1 = 0;

                                                as = new String[11];

                                                while(stringtokenizer1.hasMoreTokens())

                                                    as[k1++] = stringtokenizer1.nextToken();

                                                if(k1 < 3)

                                                    continue label0;

                                            } while((l1 = Integer.parseInt(as[0])) < a_int_fld || l1 >= a_int_fld + 8);

                                            if(b_int_fld != 1)

                                                continue label1;

                                            d_int_fld = 1;

                                            a_java_lang_String_array1d_fld[l1 & 7] = s1.substring(as[0].length() + 1, s1.indexOf(as[k1 - 2]) - 1);

                                            if(as[k1 - 2].charAt(2) == '1')

                                                a_int_array1d_fld[l1 & 7] = 3;

                                            else

                                            if(as[k1 - 2].charAt(1) == '1')

                                                a_int_array1d_fld[l1 & 7] = 2;

                                            else

                                            if(as[k1 - 2].charAt(0) == '1')

                                                a_int_array1d_fld[l1 & 7] = 1;

                                            else

                                                a_int_array1d_fld[l1 & 7] = 0;

                                            i++;

                                        } while(true);

                                    while(k1 < 3);

                                    a_java_awt_Label_array1d_fld[i].setText(a_java_lang_String_array1d_fld[l1 & 7]);

                                    a_java_awt_Label_array1d_fld[i].setVisible(true);

                                    b_java_awt_Label_array1d_fld[i].setVisible(true);

                                    b_java_awt_Label_array1d_fld[i].setText(as[0]);

                                    if(a_int_array1d_fld[l1 & 7] != 0)

                                    {

                                        if(a_int_array1d_fld[l1 & 7] == 2)

                                            as[1] = "Lost";

                                        else

                                        if(a_int_array1d_fld[l1 & 7] == 3)

                                            as[1] = "ID";

                                        c_java_awt_Label_array1d_fld[i].setVisible(true);

                                    }

                                    c_java_awt_Label_array1d_fld[i].setText(as[1]);

                                    c_java_awt_Label_array1d_fld[i].setVisible(true);

                                    if(a_boolean_fld && b_int_fld == 0)

                                        a_java_io_PrintWriter_fld.print(as[0] + "," + as[1] + "," + as[2] + ",");

                                    l1 = Integer.parseInt(as[2]);

                                    int k2 = 0;

                                    if(l1 > 0 && l1 < 250 && k1 > 3)

                                    {

                                        for(int i2 = 3; i2 < k1; i2 += 2)

                                        {

                                            if(as[i2].equals("Disabled"))

                                                continue;

                                            a_java_awt_Label_array2d_fld[i][k2].setVisible(true);

                                            b_java_awt_Label_array2d_fld[i][k2].setVisible(true);

                                            a_java_awt_Label_array2d_fld[i][k2].setText(as[i2]);

                                            b_java_awt_Label_array2d_fld[i][k2].setText(as[i2 + 1]);

                                            if(as[i2 + 1].equals("F") || as[i2 + 1].equals("C"))

                                            {

                                                a_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(255, 0, 0));

                                                b_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(255, 0, 0));

                                            } else

                                            if(as[i2 + 1].equals("%"))

                                            {

                                                a_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(0, 153, 0));

                                                b_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(0, 153, 0));

                                            } else

                                            if(as[i2 + 1].equals("mbar") || as[i2 + 1].equals("mmHg") || as[i2 + 1].equals("inHg"))

                                            {

                                                a_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(0, 102, 204));

                                                b_java_awt_Label_array2d_fld[i][k2].setForeground(new Color(0, 102, 204));

                                            }

                                            if(a_boolean_fld && b_int_fld == 0)

                                                a_java_io_PrintWriter_fld.print(as[i2] + "," + as[i2 + 1] + ",");

                                            k2++;

                                        }

                                    }

                                    for(int j2 = k2; j2 < 4; j2++)

                                    {

                                        a_java_awt_Label_array2d_fld[i][j2].setVisible(false);

                                        b_java_awt_Label_array2d_fld[i][j2].setVisible(false);

                                    }

                                    i++;

                                } while(i != 8);

                                if(a_boolean_fld && b_int_fld == 0)

                                {

                                    a_java_io_PrintWriter_fld.print("\n");

                                    a_java_io_PrintWriter_fld.flush();

                                }

                                a_long_fld = (a_long_fld + 1L) % 0x7fffffffffffffffL;

                            }

                            e_int_fld = 100;

                        }

                    } else

                    if(i1 == 0)

                        e_int_fld++;

                    else

                        e_int_fld = 50;

                } while(true);

                if(c_int_fld > 100 || e_int_fld == 30 && a_java_net_Socket_fld != null)

                {

                    try

                    {

                        System.err.println(new Date() + " R" + a_int_fld + " nodata; port:" + a_java_net_Socket_fld.getLocalPort());

                        a_java_net_Socket_fld.close();

                    }

                    catch(Exception exception)

                    {

                        System.err.println("R" + a_int_fld + ": Error Closing Socket: " + exception);

                    }

                    a_java_net_Socket_fld = null;

                }

                for(int j = i; j < 8; j++)

                {

                    a_java_awt_Label_array1d_fld[j].setVisible(false);

                    b_java_awt_Label_array1d_fld[j].setVisible(false);

                    c_java_awt_Label_array1d_fld[j].setVisible(false);

                    for(int j1 = 0; j1 < 4; j1++)

                    {

                        a_java_awt_Label_array2d_fld[j][j1].setVisible(false);

                        b_java_awt_Label_array2d_fld[j][j1].setVisible(false);

                    }

                }

                if(b_int_fld == 0 && a_long_fld % 20L == 0L)

                {

                    b_int_fld = 1;

                    d_int_fld = 0;

                } else

                if(b_int_fld == 0)

                    try

                    {

                        int k = 0;

                        while(k < c_int_fld)

                        {

                            Thread.sleep(1000L);

                            k++;

                        }

                    }

                    catch(InterruptedException _ex) { }

                else

                if(b_int_fld == 1 && d_int_fld == 1)

                {

                    b_int_fld = 0;

                    try

                    {

                        int l = 0;

                        while(l < c_int_fld)

                        {

                            Thread.sleep(1000L);

                            l++;

                        }

                    }

                    catch(InterruptedException _ex) { }

                }

            }

            catch(Exception exception1)

            {

                System.err.println("R" + a_int_fld + ": Error reading socket: " + exception1 + "--" + s);

            }

        } while(true);

    }

    public boolean action(Event event, Object obj)

    {

        if(event.target instanceof Button)

        {

            if(((String) (obj = obj.toString())).substring(0, 12).compareTo("Data Logging") == 0)

                if(!a_boolean_fld)

                {

                    a_javax_swing_JFileChooser_fld = new JFileChooser();

                    if((obj = a_javax_swing_JFileChooser_fld.showSaveDialog(this)) == 0)

                    {

                        if(a_java_io_File_fld != null)

                            a_java_io_PrintWriter_fld.close();

                        if(a_javax_swing_JFileChooser_fld.getSelectedFile().getName().lastIndexOf('.') == -1)

                            a_javax_swing_JFileChooser_fld.setSelectedFile(new File(a_javax_swing_JFileChooser_fld.getSelectedFile().getAbsoluteFile() + ".csv"));

                        else

                        if(!a_javax_swing_JFileChooser_fld.getSelectedFile().getName().endsWith(".csv"))

                        {

                            ((JDialog) (obj = new JDialog())).setTitle("Save Current Graph");

                            ((JDialog) (obj)).add(new Label("File Type Error: file must be saved in TEXT format(.csv)"));

                            ((JDialog) (obj)).resize(330, 80);

                            ((JDialog) (obj)).show();

                        }

                        if(a_javax_swing_JFileChooser_fld.getSelectedFile().getName().endsWith(".csv"))

                        {

                            a_java_io_File_fld = a_javax_swing_JFileChooser_fld.getSelectedFile();

                            try

                            {

                                a_java_io_FileWriter_fld = new FileWriter(a_java_io_File_fld);

                                a_java_io_PrintWriter_fld = new PrintWriter(a_java_io_FileWriter_fld);

                            }

                            // Misplaced declaration of an exception variable

                            catch(Object obj)

                            {

                                System.err.println("R" + a_int_fld + ": IOException:");

                                ((IOException) (obj)).printStackTrace();

                                return false;

                            }

                            a_boolean_fld = true;

                            a_java_awt_Button_fld.setLabel("Data Logging: ACTIVE");

                            a_long_fld = 0L;

                            ((JDialog) (obj = new JDialog())).setTitle("Data Logging");

                            ((JDialog) (obj)).setLayout(new FlowLayout());

                            ((JDialog) (obj)).add(new Label("Data logging in " + a_java_io_File_fld));

                            ((JDialog) (obj)).resize(500, 80);

                            ((JDialog) (obj)).show();

                        }

                    } else

                    {

                        ((JDialog) (obj = new JDialog())).setTitle("Data Logging");

                        ((JDialog) (obj)).setLayout(new FlowLayout());

                        ((JDialog) (obj)).add(new Label("Data logging inactivated"));

                        ((JDialog) (obj)).resize(230, 80);

                        ((JDialog) (obj)).show();

                    }

                } else

                {

                    a_boolean_fld = false;

                    a_java_awt_Button_fld.setLabel("Data Logging: INACTIVE");

                    if(a_java_io_PrintWriter_fld != null)

                        a_java_io_PrintWriter_fld.close();

                    a_java_io_File_fld = null;

                    ((JDialog) (obj = new JDialog())).setTitle("Data Logging");

                    ((JDialog) (obj)).setLayout(new FlowLayout());

                    ((JDialog) (obj)).add(new Label("Data logging inactivated"));

                    ((JDialog) (obj)).resize(230, 80);

                    ((JDialog) (obj)).show();

                }

        } else

        if(event.target == a_java_awt_TextField_fld)

        {

            c_int_fld = Integer.parseInt(a_java_awt_TextField_fld.getText());

            if(c_int_fld < 1)

                c_int_fld = 1;

            else

            if(c_int_fld > 0x15180)

                c_int_fld = 0x15180;

            a_java_awt_TextField_fld.setText(Integer.toString(c_int_fld));

            return true;

        }

        return true;

    }

    private File a_java_io_File_fld;

    private FileWriter a_java_io_FileWriter_fld;

    private PrintWriter a_java_io_PrintWriter_fld;

    private boolean a_boolean_fld;

    private Button a_java_awt_Button_fld;

    private JFileChooser a_javax_swing_JFileChooser_fld;

    private long a_long_fld;

    private Label a_java_awt_Label_array1d_fld[];

    private Label b_java_awt_Label_array1d_fld[];

    private Label c_java_awt_Label_array1d_fld[];

    private Label a_java_awt_Label_array2d_fld[][];

    private Label b_java_awt_Label_array2d_fld[][];

    private Label a_java_awt_Label_fld;

    private Label b_java_awt_Label_fld;

    private Label c_java_awt_Label_fld;

    private TextField a_java_awt_TextField_fld;

    private Label d_java_awt_Label_fld;

    private Label e_java_awt_Label_fld;

    private int a_int_fld;

    private String a_java_lang_String_fld;

    private String a_java_lang_String_array1d_fld[];

    private int a_int_array1d_fld[];

    private int b_int_fld;

    private int c_int_fld;

    private int d_int_fld;

    private int e_int_fld;

    private Thread a_java_lang_Thread_fld;

    private Socket a_java_net_Socket_fld;

    private PrintWriter b_java_io_PrintWriter_fld;

    private BufferedInputStream a_java_io_BufferedInputStream_fld;

}

Tagged:
This discussion has been closed.