So I am building this RFID tracking system, which essentially consists of a RFID reader and tags. So I have programmed the Tags and connected the reader through RS-232 port of my computer.I open the hyper terminal or the console for the serial communication. Whenever the tag is detected the some ID shows up in the Hyper Terminal. That means everything is fine.

Now to achieve the same in java, i.e Serial Communication. I am using javax.comm API for serial communication which is achieved from this code.

import java.io.*;
import java.util.*;
 
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("COM1")) {
        //                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(9600,
            SerialPort.DATABITS_8,
            SerialPort.STOPBITS_1,
            SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {System.out.println(e);}
    readThread = new Thread(this);
    readThread.start();
}
 
public void run() {
    try {
        Thread.sleep(20000);
    } catch (InterruptedException e) {System.out.println(e);}
}
 
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[20];
 
        try {
            while (inputStream.available() > 0) {
                int numBytes = inputStream.read(readBuffer);
            }
            System.out.print(new String(readBuffer));
        } catch (IOException e) {System.out.println(e);}
        break;
    }
}}


So what i need to achieve is that whenever the tag is swapped with the reader, the tagid that is recieved by us from COM port, would go into a database along with its time stamp.

So I created this database by :

create table track(
tagid number(8),
timet timestamp
);
So what should I do so that whenever a card is swiped this table gets entered by the tag id (received by COM port) and the time and date of the swipe (Timestamp of the swipe).

Any help would be appreciated.