Thursday, October 30, 2014

Export/Generat user scripts in physical directory in Oracle Database.

In this article I am try to export user scripts in my physical directory. I have use an external table for maintain schema which I want to export.  


--- CREATING DIRECTORY FOR WRITE FILE

CREATE OR REPLACE DIRECTORY
DATA_DIR AS
'D:\DUMP\';

--- GRANT READ AND WRITE PERMITION TO SPECIFIC USER

GRANT READ, WRITE ON DIRECTIORY DATA_DIR TO TEST_USER;

-- CREATING EXTERNAL TABLE FOR COLLECT USER INFORMATION

CREATE TABLE EXT_TABLE
(
   USER_NAME         VARCHAR2 (200),
   REPLACE_ALLOWED   VARCHAR2 (10),
   COMMENTS          VARCHAR2 (300)
)
ORGANIZATION EXTERNAL
    (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY DATA_DIR
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
LOGFILE 'data.log'
BADFILE 'data.txt'
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
)
LOCATION('USER_REPLACE.csv')
)
REJECT LIMIT UNLIMITED;

-- CREATING PROCEDURE TO WRITE USER SCRIPTS

CREATE OR REPLACE PROCEDURE SP_USER_PRIVILEGES_SCRIPTS
(P_DIRECTORY VARCHAR2,P_FILE_NAME VARCHAR2)
IS
  V_CHNK_SIZE PLS_INTEGER;
  V_CLOB_USER CLOB;
  V_CLOB_DATA CLOB;
  V_OUTPUT UTL_FILE.FILE_TYPE;
  V_FILE_NAME VARCHAR2(1000);
 
  PROCEDURE USER_FILE_WRITE(P_WRITE_TAG VARCHAR2) IS
      BEGIN
        V_FILE_NAME:=P_FILE_NAME||'_'||P_WRITE_TAG||'.SQL';
        V_CLOB_DATA:=NULL;
       
        FOR INDUSR IN (SELECT USER_NAME  FROM EXT_TABLE WHERE REPLACE_ALLOWED='Y') LOOP

         BEGIN
            SELECT REPLACE(REPLACE(DBMS_METADATA.GET_DDL(P_WRITE_TAG, INDUSR.USER_NAME),'"',' '),'
 ','')||';'  INTO V_CLOB_USER
            FROM DUAL;
          END;
          V_CLOB_DATA:=V_CLOB_DATA||V_CLOB_USER;
         END LOOP;
        
          V_OUTPUT := UTL_FILE.FOPEN( P_DIRECTORY, V_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

          V_CHNK_SIZE := 3000;
          FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
          LOOP
           
            UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
             UTL_FILE.FFLUSH(V_OUTPUT);
          END LOOP;
       
          UTL_FILE.FCLOSE(V_OUTPUT);
     END;
    
   PROCEDURE GRANT_FILE_WRITE(P_WRITE_TAG VARCHAR2) IS
  BEGIN
    V_FILE_NAME:=P_FILE_NAME||'_'||P_WRITE_TAG||'.SQL';
    V_CLOB_DATA:=NULL;
 BEGIN
        FOR INDUSR IN (SELECT USER_NAME  FROM EXT_TABLE WHERE REPLACE_ALLOWED='Y') LOOP

         BEGIN
            SELECT REPLACE(REPLACE(REPLACE(DBMS_METADATA.GET_GRANTED_DDL(P_WRITE_TAG, INDUSR.USER_NAME),'"',' '),'
 ',';'),' . ','.')  INTO V_CLOB_USER
            FROM DUAL;
          END;
          V_CLOB_DATA:=V_CLOB_DATA||V_CLOB_USER;
         END LOOP;
  END;
  V_OUTPUT := UTL_FILE.FOPEN( P_DIRECTORY, V_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

  V_CHNK_SIZE := 3000;
  FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
  LOOP
   
    UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
    UTL_FILE.FFLUSH(V_OUTPUT);
  END LOOP;
  UTL_FILE.FCLOSE(V_OUTPUT);
 END;

 BEGIN

  USER_FILE_WRITE('USER');
  GRANT_FILE_WRITE('ROLE_GRANT');
  GRANT_FILE_WRITE('SYSTEM_GRANT');
  GRANT_FILE_WRITE('OBJECT_GRANT');
 
END;
/

-- EXECUTE PROCEDURE AND COLLECT SCRIPTS FROM DIRECTORIES

EXEC SP_USER_PRIVILEGES_SCRIPTS('DATA_DIR','TEST_SCRIPTS');

Export BLOB from database to physical directory.


 I have seen many people are failed to extract image from database to physical directory (in my article comments ) for this reason today I have make this procedure for export blob file.

You can export BLOB file using the following instruction.

1. Create an directory .

CREATE OR REPLACE DIRECTORY
DATA_DIR AS
'D:\DUMP\';

2. Create procedure.

CREATE OR REPLACE PROCEDURE SP_EXPORT_IMAGE (P_BLOB_DATA IN BLOB,P_FILE_NAME VARCHAR2,P_DIRECTORY VARCHAR2 )
AS
V_CLOB_DATA CLOB;
V_DATA VARCHAR2(32767);
V_START PLS_INTEGER := 1;
V_END PLS_INTEGER := 32767;
  V_OUTPUT UTL_FILE.FILE_TYPE;
  V_CHNK_SIZE PLS_INTEGER;
BEGIN
DBMS_LOB.CREATETEMPORARY(V_CLOB_DATA, TRUE);

FOR I IN 1..CEIL(DBMS_LOB.GETLENGTH(P_BLOB_DATA) / V_END)
LOOP

   V_DATA := UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(P_BLOB_DATA, V_END, V_START));

DBMS_LOB.WRITEAPPEND(V_CLOB_DATA, LENGTH(V_DATA), V_DATA);
V_START := V_START + V_END;
END LOOP;

V_CHNK_SIZE := 3000;

V_OUTPUT := UTL_FILE.FOPEN(P_DIRECTORY, P_FILE_NAME, 'wb', MAX_LINESIZE => 32767 );

  FOR I IN 1 .. CEIL( LENGTH( V_CLOB_DATA ) / V_CHNK_SIZE )
  LOOP
    UTL_FILE.PUT_RAW( V_OUTPUT, UTL_RAW.CAST_TO_RAW( SUBSTR( V_CLOB_DATA, ( I - 1 ) * V_CHNK_SIZE + 1, V_CHNK_SIZE ) ) );
    UTL_FILE.FFLUSH(V_OUTPUT);
  END LOOP;
       
  UTL_FILE.FCLOSE(V_OUTPUT);

END SP_EXPORT_IMAGE;


---------------- Export Blob File in physical directory. ------------------


DECLARE
V_BLOB BLOB;
 V_FILE_NAME VARCHAR2(300);
BEGIN
SELECT IMAGE_FRONT, DATA_NO INTO V_BLOB, V_FILE_NAME
FROM OUTWDCLR_REP
WHERE DATA_NO=77771613;

SP_EXPORT_IMAGE(V_BLOB,V_FILE_NAME||'.JPG','DATA_DIR');
END;

Tuesday, October 28, 2014

Replace character from Oracle Procedure, Function, Package and Trigger

You can replace character and compile Procedure, Function, Package and Trigger using this block.
----------------------------------------------------------------

DECLARE
  V_CLOB_USER CLOB;
  V_SEARCHING VARCHAR2(300):='FROM_USER';
  V_REPLACE_WITH VARCHAR2(300):='TO_USER';
 BEGIN
       
        FOR INDUSR IN (SELECT DISTINCT NAME, REPLACE (TYPE, 'PACKAGE BODY', 'PACKAGE') TYPE,U.OWNER OWNER_OBJECT
                          FROM DBA_SOURCE U, DBA_OBJECTS O
                         WHERE     O.OBJECT_NAME = U.NAME
                             AND U.OWNER = O.OWNER
                             AND U.OWNER = V_SEARCHING
                               AND TYPE IN ('PROCEDURE', 'FUNCTION', 'PACKAGES', 'TRIGGER', 'PACKAGE BODY')) LOOP

         BEGIN

         SELECT REPLACE(DBMS_METADATA.GET_DDL(INDUSR.TYPE,INDUSR.NAME,INDUSR.OWNER_OBJECT),V_SEARCHING,V_REPLACE_WITH) INTO V_CLOB_USER FROM DUAL;

         EXECUTE IMMEDIATE V_CLOB_USER;
           EXCEPTION
                    WHEN OTHERS THEN
                    DBMS_OUTPUT.PUT_LINE(SQLERRM);
          END;

   END LOOP;
END;

Wednesday, October 15, 2014

Send SMS using GSM Modem from Oracle Database

Send SMS using GSM Modem from Oracle Database

 SMSLib:

SMSLib provides a universal texting API, which can be used for sending and receiving messages via GSM modems.

Pre-requisites:

JDK 1.6 or higher
 JAVA Compiler

Configure SMSLib: You need the following files to configure SMSLib. You can find all of this file in Configuration_Files folder.

Download Files

Click the download link




1.       javax.comm.properties
2.       comm.jar
3.       RXTXcomm.jar
4.       win32com.dll
JAVA_HOME is path where jdk is installed

Step 1:- Copy comm.jar to
·         %JAVA_HOME%/lib  
[ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]
·         %JAVA_HOME%/jre/lib/ext
[ In my case C:\Program Files\ Java\jdk1.7.0_03\jre\lib\ext ]

Step 2:- Copy win32com.dll to
·         %JAVA_HOME%/bin
[In my case C:\Program Files\ Java\jdk1.7.0_03\bin ]
·         %JAVA_HOME%/jre/bin
      [ In my case C:\Program Files\ Java\jdk1.7.0_03\jre\bin ]
·         %windir%System32
             [ In my case C:\Windows\System32 ]

Step 3 : Copy javax.comm.properties to
·         %JAVA_HOME%/lib
            [ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]
·         %JAVA_HOME%/jre/lib
            [ In my case C:\Program Files\Java\jdk1.7.0_03\jre\lib ]
Step 4 : Copy RXTXcomm.jar to
·         %JAVA_HOME%/ jre/lib/ext
            [ In my case C:\Program Files\ Java\jdk1.7.0_03\lib ]

1.     Now open your NetBeans IDE

2.     You can find your modem port using CommunicationPortTest class. After finding port and bauds enter your port and bauds in SendSMS class. Please see red color line.

3.     Add the following jar files in your libraries (log4j-1.2.16.jar, ojdbc6.jar, smslib-3.5.1.jar)

4.     Create the following two class (SendSMS, DBCP)

5.     Create one table (SMS_LIST)

6.     Now insert row in SMS_LIST table and run project you can get SMS.

SendSMS Class


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;
import org.smslib.AGateway;
import org.smslib.AGateway.GatewayStatuses;
import org.smslib.IOutboundMessageNotification;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
import java.sql.*;
/**
 *
 * @author rajib.pradhan
 */

public class SendSMS extends Thread {
    OutboundNotification outboundNotification;
    StringBuffer sql1;  
    SerialModemGateway gateway;
    String smsGatewayStatus = "";
    GatewayStatuses status;
    int i=0;
    public SendSMS() {
        try {
           
            outboundNotification = new OutboundNotification();
            SerialModemGateway gateway = new SerialModemGateway("modem.COM27", "COM27", 9600, "", "");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            Service.getInstance().setOutboundMessageNotification(outboundNotification);
            Service.getInstance().addGateway(gateway);
            Service.getInstance().startService();
            status = gateway.getStatus();
            smsGatewayStatus = status.toString();
        } catch (Exception e) {
            System.out.println("EXCEPTION gateway.getStatus : "+gateway.getStatus());
            status = gateway.getStatus();
            smsGatewayStatus = status.toString();
            e.printStackTrace();
            System.out.println("Exception e.getMessage: " + e.getMessage());
            System.out.println("Exception cause: " + e.getCause());
        }
    }

    public void sendSMStoMobile() throws Exception {
        if (smsGatewayStatus.equals("STOPPED")) {
            return;
        }

        DBCP dbcp = DBCP.getInstance();
        Connection connection = dbcp.getConnection();
        Statement statement = connection.createStatement();
        ResultSet resultSet = null;
       
        try {
            sql1 = new StringBuffer();
            sql1.append("SELECT MOBILE_NUMBER, MESSAGE, TRANUM ");
            sql1.append("FROM SMSGATEWAY.SMS_LIST ");
            sql1.append("WHERE SEND_STATUS = 'N' ");
            resultSet = statement.executeQuery(sql1.toString());
           
            while (resultSet.next()) {
              
                String destMobileNo = resultSet.getString(1);
                System.out.println("Phone Number "+resultSet.getString(1));
                String message = resultSet.getString(2);
                String tranNumber = resultSet.getString(3);
                OutboundMessage sms = new OutboundMessage(destMobileNo, message);
                Service.getInstance().sendMessage(sms);
                //Update Table After Send Message
                String updateQuery = "UPDATE SMSGATEWAY.SMS_LIST SET SEND_STATUS = 'Y' WHERE TRANUM = " + tranNumber ;
                if(i<20)
                {
               System.out.print(tranNumber+": Y, ");
               
                }
                if(i==20){
                System.out.print(tranNumber+": Y, "+"\n");
                i=0;
                }
                statement.executeUpdate(updateQuery);
                connection.commit();
                i=i+1;
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (resultSet != null) {
                resultSet.close();
            }
            if (statement != null) {
                statement.close();
            }
            dbcp.releaseConnection(connection);
        }
    }

    public class OutboundNotification implements IOutboundMessageNotification {

        public void process(AGateway gateway, OutboundMessage msg) {
            System.out.println(msg);
        }
    }

    public void run() {
        while (true) {
            try {
                sendSMStoMobile();
                this.sleep(1000);
            } catch (Exception e) {
            }
        }
    }

    public static void main(String[] args) throws Exception {
        SendSMS sendSMSFromDB = new SendSMS();
        sendSMSFromDB.start();
    }

    private void getModemInformation(SerialModemGateway gateway) throws Exception{
        System.out.println();
        System.out.println("Modem Information:");
       
        System.out.println("  Model: " + gateway.getModel());
        System.out.println("  Serial No: " + gateway.getSerialNo());
        System.out.println("  SIM IMSI: " + gateway.getImsi());
        System.out.println("  Signal Level: " + gateway.getSignalLevel() + " dBm");
        System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
        System.out.println("  Manufacturer: " + gateway.getManufacturer());
        System.out.println();
    }
}

Database Connection (DBCP) Class


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Vector;
import java.util.Stack;

/**
 *
 * @author rajib.pradhan
 */
/*
 *
 * Database Connection Information
 *
 */

public class DBCP implements Runnable {

    private static DBCP connectionPool;
    private Stack pool;
    private Vector busyConnections;
    private int MAX_CONNECTIONS = 10000;
    private int MIN_CONNECTIONS = 1;
    private long timeout;
    private String sDriver;
    private String sDBUrl;
    private String sUsername;
    private String sPassword;

    private DBCP(String sDriver,
                 String sUrl,
                 String sUserName,
                 String sPassword,
                 int sMaxConnection,
                 int sMinConnection,
                 long sTimeOut) throws SQLException {
       
        this.timeout = sTimeOut;
        this.sDriver = sDriver;
        this.sDBUrl = sUrl;
        this.sUsername = sUserName;
        this.sPassword = sPassword;
        this.MAX_CONNECTIONS = sMaxConnection;
        this.MIN_CONNECTIONS = sMinConnection;
        busyConnections = new Vector();
        pool = new Stack();
        for (int i = 0; i < MIN_CONNECTIONS; i++) {
            pool.push(makeNewConnection());
        }
    }

    public static DBCP getInstance() {
        if (connectionPool == null) {
            try {
                connectionPool =
                        new DBCP(
                        "oracle.jdbc.OracleDriver",
                       "jdbc:oracle:thin:@localhost:1521:ORCL",
                        "SMSGATEWAY",
                        "SMSGATEWAY",
                        10,
                        5,
                        30000);
            } catch (SQLException _sqlex) {
                _sqlex.printStackTrace();
            }
        }
        return connectionPool;
    }

    public synchronized Connection getConnection() throws SQLException, InterruptedException {
        Connection connection = null;
        if (connectionPool != null) {
            if (pool.size() != 0) {
                connection = (Connection) pool.pop();
                busyConnections.add(connection);
            } else {
                if (getTotalConnections() >= MAX_CONNECTIONS) {
                    while (busyConnections.size() < MAX_CONNECTIONS) {
                        connection = (Connection) pool.pop();
                        if (connection != null) {
                            connection.close();
                        }
                    }
                } else {
                    makeBackgroundConnection();
                    wait();
                    connection = getConnection();
                }
            }
        }
        return connection;
    }

    protected int getTotalConnections() {
        return pool.size() + busyConnections.size();
    }

    private void makeBackgroundConnection() throws SQLException {
        try {
            Thread connectionThread = new Thread(this);
            connectionThread.start();
        } catch (Exception _ex) {
            throw new SQLException("Max Limit of connections exceeded");
        }
    }

    private synchronized Connection makeNewConnection() throws SQLException {
        try {
            Class.forName(sDriver);
            Connection connection =
                    DriverManager.getConnection(sDBUrl, sUsername, sPassword);
            connection.setAutoCommit(false);
            return connection;
        } catch (ClassNotFoundException cnfe) {
            throw new SQLException("Can't find class for driver: " + sDriver);
        }
    }

    /**
     * run() function for making a new connection from the
     * backgroud called by makeBackgroundConnection()
     */
    public void run() {
        synchronized (this) {
            try {
                Connection con = makeNewConnection();
                pool.push(con);
                notifyAll();
            } catch (Exception _ex) {
            }
        }
    }

    /**
     *
     * @return Information about this connection pool
     */
    public synchronized void releaseConnection(Connection con) {
        pool.push(con);
        busyConnections.remove(con);
        notifyAll();
    }

    public synchronized String toString() {
        String info =
                "ConnectionPool("
                + sDBUrl
                + ","
                + sUsername
                + ")"
                + ", available="
                + pool.size()
                + ", busy="
                + busyConnections.size()
                + ", max="
                + MAX_CONNECTIONS;
        return info;
    }

    /**
     *
     * @throws SQLException
     */
    private synchronized void closeAllConnections() throws SQLException {
        while (!pool.isEmpty()) {
            try {
                ((Connection) pool.pop()).close();
            } catch (Exception _ex) {
                throw new SQLException("Unable to close the Connection");
            }
        }
        pool = new Stack();
        for (int i = 0; i < busyConnections.size(); i++) {
            try {
                ((Connection) busyConnections.get(i)).close();
                busyConnections.remove(i);
            } catch (Exception _ex) {
                throw new SQLException("Unable to close the Connection");
            }
        }
        busyConnections = new Vector();
    }

    /**
     *
     * @throws java.lang.Throwable
     */
    protected void finalize() throws java.lang.Throwable {
        try {
            closeAllConnections();
        } catch (Exception _ex) {
        }
        super.finalize();
    }
}

Port finding class (CommunicationPortTest.class)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smsgetway;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Formatter;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import org.smslib.helper.CommPortIdentifier;
import org.smslib.helper.SerialPort;

/**
 *
 * @author rajib.pradhan
 */

public class CommunicationPortTest {

    private static final String _NO_DEVICE_FOUND = "No Device Found.";
    private final static Formatter _formatter = new Formatter(System.out);
    static CommPortIdentifier portId;
    static Enumeration<CommPortIdentifier> portList;
    static int bauds[] = {9600, 14400, 19200, 28800, 33600, 38400, 56000, 57600, 115200};

    /**
     * Wrapper around {@link CommPortIdentifier#getPortIdentifiers()} to be
     * avoid unchecked warnings.
     */
    private static Enumeration<CommPortIdentifier> getCleanPortIdentifiers() {
        return CommPortIdentifier.getPortIdentifiers();
    }

    public static void main(String[] args) {
        System.out.println("\nSearching for devices...");
        portList = getCleanPortIdentifiers();
        while (portList.hasMoreElements()) {
            portId = portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                _formatter.format("%nFound port: %-5s%n", portId.getName());
                for (int i = 0; i < bauds.length; i++) {
                    SerialPort serialPort = null;
                    _formatter.format("       Trying at %6d...", bauds[i]);
                    try {
                        InputStream inStream;
                        OutputStream outStream;
                        int c;
                        String response;
                        //serialPort = portId.open("SMSLibCommTester", 1971);
                        serialPort = portId.open("SMSAPP", 1971);
                        serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN);
                        serialPort.setSerialPortParams(bauds[i], SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                        inStream = serialPort.getInputStream();
                        outStream = serialPort.getOutputStream();
                        serialPort.enableReceiveTimeout(1000);
                        c = inStream.read();
                        while (c != -1) {
                            c = inStream.read();
                        }
                        outStream.write('A');
                        outStream.write('T');
                        outStream.write('\r');
                        Thread.sleep(1000);
                        response = "";
                        StringBuilder sb = new StringBuilder();
                        c = inStream.read();
                        while (c != -1) {
                            sb.append((char) c);
                            c = inStream.read();
                        }
                        response = sb.toString();
                        if (response.indexOf("OK") >= 0) {
                            try {
                                System.out.print("  Getting Info...");
                                outStream.write('A');
                                outStream.write('T');
                                outStream.write('+');
                                outStream.write('C');
                                outStream.write('G');
                                outStream.write('M');
                                outStream.write('M');
                                outStream.write('\r');
                                response = "";
                                c = inStream.read();
                                while (c != -1) {
                                    response += (char) c;
                                    c = inStream.read();
                                }
                                System.out.println(" Found: " + response.replaceAll("\\s+OK\\s+", "").replaceAll("\n", "").replaceAll("\r", ""));
//                                JOptionPane.showMessageDialog(null," Found: " + response.replaceAll("\\s+OK\\s+", "").replaceAll("\n", "").replaceAll("\r", ""), "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                            } catch (Exception e) {
                                System.out.println(_NO_DEVICE_FOUND);
//                                JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                            }
                        } else {
                            System.out.println(_NO_DEVICE_FOUND);
//                            JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                        }
                    } catch (Exception e) {
                        System.out.print(_NO_DEVICE_FOUND);
//                        JOptionPane.showMessageDialog(null, _NO_DEVICE_FOUND, "Warning",
//                                JOptionPane.WARNING_MESSAGE);
                        Throwable cause = e;
                        while (cause.getCause() != null) {
                            cause = cause.getCause();
                        }
                        System.out.println(" (" + cause.getMessage() + ")");
                    } finally {
                        if (serialPort != null) {
                            serialPort.close();
                        }
                    }
                }
            }
        }
        System.out.println("\nCommunication Test Completed.");
//        JOptionPane.showMessageDialog(null, "Communication Test Completed.", "Information",
//                                JOptionPane.INFORMATION_MESSAGE);
    }
}

Table Scripts

CREATE TABLE SMS_LIST
(
  MOBILE_NUMBER  VARCHAR2(20 BYTE),
  MESSAGE        VARCHAR2(300 BYTE),
  SEND_STATUS    CHAR(1 BYTE)                   DEFAULT 'N',
  TRANUM         VARCHAR2(30 BYTE)
)