How to insert Unicode Character on your database table when your Oracle database does not have Unicode Character Set?

How to insert Unicode Character on your database table when your Oracle database does not have Unicode Character Set?

This post is about How to insert Unicode character (like Hindi) when your database not support Unicode Charset.

To check your database support Unicode character or not you can use following query

 

SELECT value$ FROM sys.props$ WHERE name = 'NLS_CHARACTERSET' ;

 

If it will return WE8ISO8859P1 that means it is not support Unicode characters.

For binding or defining Java string variables to SQL NVARCHAR2 datatypes, Oracle provides an extended PreparedStatement which has the setFormOfUse() method through which you can explicitly specify the target column of a bind variable to be a SQL NVARCHAR2 datatype. The following code illustrates how to bind a Java string to an NVARCHAR2 column.

 

  1. So the first step is to create table and set data type to NVARCHAR2 for columns where you want to store Unicode character.
CREATE TABLE INSURANCE_DATA
(
  SCMCD           VARCHAR2(20 BYTE)             NOT NULL,

  MOBILE_NO       NUMBER                        NOT NULL,

  SUBS_NAME       NVARCHAR2(40)                 NOT NULL,

  ADDR            NVARCHAR2(100)                NOT NULL,

  CITY            NVARCHAR2(20)                 NOT NULL,

  DISTRICT        NVARCHAR2(20)                 NOT NULL,

  DOB             DATE                          NOT NULL,

  OCCUPATION      NVARCHAR2(20)                 NOT NULL,

  NOMINEE_NAME    NVARCHAR2(40)                 NOT NULL

)

2.Then create method on AMImpl to insert data to table.

setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR) used to define this particular column is NVARCHAR type.

public String insertInsuranceData(String DIVN, String SCMCD,
                                      String MOBILE_NO, String SUBS_NAME,
                                      String ADDR, String CITY,
                                      String DISTRICT, String DOB,
                                      String OCCUPATION, String NOMINEE_NAME,
                                      String ADHAAR_NO,
                                      String CONFIRM_STATUS) {
        
        String msg="";
        String sql =
            "insert into sr_insurance_data(SCMCD,MOBILE_NO,SUBS_NAME,ADDR,CITY,DISTRICT,DOB,OCCUPATION,NOMINEE_NAME) values(?,?,?,?,?,?,?,?,?)";

        oracle.jdbc.OraclePreparedStatement pstmt =
            (oracle.jdbc.OraclePreparedStatement)this.getDBTransaction().createPreparedStatement(sql,
                                                                                                 0);

        int i = 1;

      
        try {
            pstmt.setString(i++, SCMCD);
            pstmt.setString(i++, MOBILE_NO);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, SUBS_NAME);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, ADDR);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, CITY);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, DISTRICT);
            pstmt.setString(i++, DOB);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, OCCUPATION);
            pstmt.setFormOfUse(i, OraclePreparedStatement.FORM_NCHAR);
            pstmt.setString(i++, NOMINEE_NAME);
            int cnt = pstmt.executeUpdate();


if(cnt>0)
{
    msg="success";
    }
            else
{
    msg="failed";
    }
        } catch (Exception ex) {
            System.out.println("Exception to insert InsuranceData" + ex);
            msg="Error:"+ex.getMessage();
        }
        return msg;
    }
3.Drag-drop method from data control to jspx page as ADF Parameter Form.

 

In my previous post I had explained How to invoke AppModule method to page using client Interface.

How to invoke Application Module Method from Page?

About Manish Pandey

Manish is a Project Leader at Jagran Prakashan Ltd, focused on Jdeveloper Fusion Web Application(specifically Oracle ADF). He shares his knowledge through the OTN Jdev/ADF Forum. He has written more than 50 article about Oracle ADF and Jdeveloper.

Leave a Reply

Your email address will not be published. Required fields are marked *

*