Serial COM Port Value in to database

Serial COM Port Value in to database

How save the serial COMport value in mysql databse. Following code is here.

package simpleread;

import java.io.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.*;

    public class SimpleRead implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static Enumeration portList;

    InputStream inputstream;
    SerialPort serialPort;
    Thread readThread;

    public static void main(String[] args) {
        portList = CommPortIdentifier.getPortIdentifiers();

        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                 if (portId.getName().equals("COM18")) {
            //                if (portId.getName().equals("/dev/term/a")) {
                    SimpleRead reader = new SimpleRead();
                }
            }
        }
    }

  public SimpleRead() {
        try {
            serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
        } catch (PortInUseException e) {System.out.println(e);}
        try {
            inputstream = serialPort.getInputStream();
        } catch (IOException e) {System.out.println(e);}
    try {
            serialPort.addEventListener(this);
    } catch (TooManyListenersException e) {System.out.println(e);}
        serialPort.notifyOnDataAvailable(true);
        try {
            serialPort.setSerialPortParams(100,
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        } catch (UnsupportedCommOperationException e) {System.out.println(e);}
        readThread = new Thread(this);
        readThread.start();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(60000);
        } catch (InterruptedException e) {System.out.println(e);}
    }

    @Override
    public void serialEvent(SerialPortEvent event) {
        switch(event.getEventType()) {
        case SerialPortEvent.BI:
        case SerialPortEvent.OE:
        case SerialPortEvent.FE:
        case SerialPortEvent.PE:
        case SerialPortEvent.CD:
        case SerialPortEvent.CTS:
        case SerialPortEvent.DSR:
        case SerialPortEvent.RI:
        case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
            break;
        case SerialPortEvent.DATA_AVAILABLE:
            byte[] readBuffer = new byte[1024];
            int[] readBuffer1 = new int[1024];
            int m=0;
            try {

                while (inputstream.available() > 0) {
                    int numBytes=0;

                        readBuffer1[m] =inputstream.read((readBuffer));
                        System.out.println(new String(readBuffer));

                         //System.out.println(inputstream);
                try {
                    Thread.sleep(6000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(SimpleRead.class.getName()).log(Level.SEVERE, null, ex);
                }

                 try
                 {
             Connection con=(Connection) ConnectionFactory.getConnection();
             System.out.println(con);


             String sql= "insert into Read2(DTST) Values(?)";


             PreparedStatement ps=con.prepareStatement(sql);
             ps.setInt(1,readBuffer1[m]);
             ps.executeUpdate();
                   // System.out.println(""+numBytes);
                   // System.out.print(new String(readBuffer));
                    System.out.println((readBuffer1[m]));

                    // System.out.println(new String(readBuffer, "US-ASCII"));
                    m++;

                }
                   catch(Exception e)
                        {

                        }

                }

            } catch (IOException e) {System.out.println(e);}
            break;
        }
    }
}

plz help.

View Answers









Related Tutorials/Questions & Answers:
Serial COM Port Value in to database
Serial COM Port Value in to database  How save the serial COMport value in mysql databse. Following code is here. package simpleread; import...(); if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
Advertisements
serial port communication using bluetooth in j2me
serial port communication using bluetooth in j2me   how to make serial port communication using bluetooth in j2me ? what r prerequisites
about value taken in java database - JDBC
about value taken in java database  how to take value from Serial port communication Hyperterminal to the java database
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class
jar file not reading input from serial port
jar file not reading input from serial port  i used a coding for getting data from serial port. JOptionbox with "port not found" message is shown... from comm port. why it is happening? i attached the coding i used. public class
ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library'
ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library...: ModuleNotFoundError: No module named 'USPP-Universal-Serial-Port-Python-Library...-Serial-Port-Python-Library python with following command: pip install USPP
Subtract a value in the database from java
Subtract a value in the database from java   Hi, i want to know how to subtract a value on a database. im using JDBC connection from access and i want to decrement the value of table "quantity" of 1 each time it passes a loop my
read value from database & alert it is available in database or not
read value from database & alert it is available in database or not  how to read value from text box and alert whether it is available in database...="text/javascript"> function check(value){ xmlHttp=GetXmlHttpObject() var
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
com in ms word
com in ms word  how to use com object to fetch data from ms word and storing it into sql database
Update value of database using hibernate.
Update value of database using hibernate.  How to update value of database using hibernate?   Hibernate provides facility to update... this by setting the value and calling the update method. session.update(employee
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
change color according to the database value
change color according to the database value  any one know how to get values from database ( 1 or 0 ) and according to that change the color ( red or green) of given list
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
how to delete the access database value in jsp
how to delete the access database value in jsp  i loaded my database data into the dropdown list box...now i want to delete the value..plz send the source code to delete the value in dropdown list box and also from database
store dynamic generated textbox value into database
store dynamic generated textbox value into database  sir, how do i store dynamically generated textbox value into the database thanks in advance
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I am getting the data's from the table that was stored in database. Now in the page in which i am getting all the data from the database has an another select
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... database and according to that i want to check the cash cheque radio button... information from database the i want to show cash radio button checked.How can i do
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I am getting the data's from the table that was stored in database. Now in the page in which i am getting all the data from the database has an another select
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  how to insert check box value to the database using jsp my code is <link href..." name="pmanager" value="Enter" ></td> <td align
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's...; <td><input name="pack_id" type="type" value
how to insert checkbox value into database using jsp
how to insert checkbox value into database using jsp  How to insert check box value to the oracle database using jsp? I want to create hotel's...; <td><input name="pack_id" type="type" value="<%= pack_id %>" size
Changing MySQL Port Number
installation directory. Change the port number to desired port number. By default port no entry will look like: port=3306 You can change the value of port...Changing MySQL Port Number  How to change the MySQL port
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from the properties file and display the data from the database. Now to load the data from
Retrieving value from multiple table in database
Retrieving value from multiple table in database  Hi fnds, I want to maintain the financial database of 20 users for 1 year and update the details in jsp page.. so i have decided to maintain the details based on month (because
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.
I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid.  I want to Populate ComBobox value from database that combox is Itemrenderer of DataGrid
getting problem in storing & retrieving value in database
getting problem in storing & retrieving value in database  Hello everyone i am doing a project where my back end is ms access & i want to store value like 5353250214 so if i store it as long int in access it wont take it &
retrieve value from database on the basis of maximum id number
retrieve value from database on the basis of maximum id number  hi, i want to retrieve value of maximum id number from the database and show that value in jTextField.when the user clicks on the button that maximum id number
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  ... dynamically from the database(mysql). after selecting the value from the dropd.... but the next textbox value is populated from database. plz help me guys
retrieve the data to text fields from database on clicking the value of combo box
retrieve the data to text fields from database on clicking the value of combo box   retrieve the data to text fields from database on clicking the value of combo box . I am not getting it plz help me out .   hi
MySQL default port number in Linux
'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port...MySQL default port number in Linux - How to find the default port number of MySQL in Linux? If you are using MySQL database server installed on the Linux
MySQL default port number and how to change it
MySQL default port number and how to change it What is default port number of MySQL Database server? This tutorial will explain you about the default port... the port number and change the value to desired number, finally save the file.ADS
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database. ... but was unable to find out exact way to fullfill the solution of selecting value from autocomplete textbox using jquery in jsp from mysql database. Kindly send me
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
ModuleNotFoundError: No module named 'com'
ModuleNotFoundError: No module named 'com'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'com' How to remove the ModuleNotFoundError: No module named 'com' error
Selecting a radio button in jquery autocomplete from database value
Selecting a radio button in jquery autocomplete from database value  I can get the data from the database using PDO to my jquery.js file. How do I force the value (1 = Handicap, 2 = Scratch, 3 = Both) to select the appropriate
use data from database table as hyperlink value - JSP-Servlet
use data from database table as hyperlink value  I'm creating a web page that allows user to search my database. The page will display partial results of my database, then the first column of the resultset was converted
How to Store Float Value into Access Database - Java Beginners
How to Store Float Value into Access Database  Hello sir,I want to Store Student Marks Percentage into Access Database in Float Value how i can Store.... To store the double value in Access database, you need to set the datatype
Problem with Double type Value in Access Database - Java Beginners
Problem with Double type Value in Access Database  Hello sir I have store Double Type Value in MS Access Databse,but when I search Record then it Gives Round Figure Value related with Percentage and I want to Store and Retrieve
how to update combobx's selected value to database with respect toselected multiple checkboxes
how to update combobx's selected value to database with respect toselected... to display records from database out.println("<tr><td>"+"<input type='checkbox' id='r1' value="+r+" name='test' >"+"</td><td>"+r+"<
how to show value and percentage in piechart sections from database using jfreechart
how to show value and percentage in piechart sections from database using jfreechart  Hii Sir, I made a pie chart from database using jfreechart.Now I need to display the values and their percentage in the sections
how to display data from database according to entered value in search field
how to display data from database according to entered value in search...;/b></td> <td>: <input type="text" name="bmi_value" id="BMI_VALUE"> </td></tr> <tr><td colspan=2 align="center">
port number - JavaMail
port number  i want james2.1.3 port number like microsoft telnet>open local host _______(some port number) i wnat that port number
how to show effect (visual) on jsp page using value from database
how to show effect (visual) on jsp page using value from database  I... i want is when the value in booking status is "booked" then the pictures shown as seats should be displayed red. when the value in booking status
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl

Ads