Handling Special Characters in Oracle JDBC et al

Hi all
I am writting a programme to do the following ..
a)Download xml data from the internet... by means of URL openConnection etc.
b) Insert parts of the xml data into a oracle database ...
Quite simple .. but ;)
How ever there is a integerity constrain of NOT NULL and UNIQUE on one of the columns on the database ...
if the word Galen exists and the code tries to insert G�len ( note � is a character on its own NOT a with ' )
its gives a Integrity violation.
I tried the following
String name = "G�len";/// comming from xml after parsing etc ...
Statement stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO ABC VALUES("+name+")" and also tried
String name = "G�len";/// comming from xml after parsing etc ...
PreparedStatement ps = conn.prepareStatement();
ps.setString(1,name);
ps.executeUpdate("INSERT INTO ABC VALUES( ? )"); and few other variations to the above procedure ....
Can any one tell me what could be the reason one possible cause could that Oracle does a transparent character set conversion on all data that it is about to update / insert ... If so what is the work around cause "Galen" and "G�len" are definatly two different names..
Also interestingly I tries to execute the following query
SELECT name FROM ABC WHERE name = 'G�len' vie jdbc using the above methods and it returns a emty result set.
So while doing a query oracle refuses to accept G�len as a existing word where as when the time comes to insert G�len it issues a integrity constraint violation :(
O/S for client code and Oracle server : Compaq Tru64 UNIX
Characters set for Compaq Tru64 UNIX V5.0A : ISO8859_1
Character set for Oracle is US7ASCII

You should use Prepared statements, it's easier and faster.
In your code you have mixed it up a bit. You wrote:
String name = "G�len";/// comming from xml after parsing etc ...
PreparedStatement ps = conn.prepareStatement();
ps.setString(1,name);
ps.executeUpdate("INSERT INTO ABC VALUES( ? )");
It should be
String name = "G�len";/// comming from xml after parsing etc ...
PreparedStatement ps = conn.prepareStatement("INSERT INTO ABC VALUES( ?)");
ps.setString(1,name);
ps.executeUpdate();
In other words, you prepare your statements and then you just use the set methods and execute. If you're looping over the XML-file you should just prepare the staments onece and then use it over and over again. This is one of the strengths with PreparedStatements.
Let's assume you have all your names in an array called name, use the following code instead:
PreparedStatement ps = conn.prepareStatement("INSERT INTO ABC VALUES( ?)");
for(int i=0; i < names.length();i++){
ps.setString(1, names);
ps.executeUpdate();
Of course, you might use ArrayList or some other Collection instead, this is just to show how to reuse PreparedStatements.
/Fredrik

Similar Messages

  • Issue in handling UTF8 characters using Oracle JDBC thin driver in Linux

    We have a standalone Java application which reads values from one table and inserts the same into another table. The value in the source table is "Türkiye Is Bankasi Gayrettepe Subesi" and the same value after inserting into the target table becomes "T�rkiye Is Bankasi Gayrettepe Subesi" (ü is getting converted to �).
    The same works fine if we run the application in Windows.

    Thanks again for looking into this. Please find the answers below
    1.What character set do you use in the database? (see NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET in the view NLS_DATABASE_PARAMETERS).
    - Both of them are UTF8
    2. What is the type of the column storing that string? (e.g. VARCHAR2, NVARCHAR2, an object type, ...)
    - Varchar2
    3. Source binary value (for "Türkiye Is Bankasi Gayrettepe Subesi")
    is
    Typ=1 Len=36:
    54,fc,72,6b,69,79,65,20,49,73,20,42,61,6e,6b,61,73,69,20,47,61,79,72,65,74,74,65,70,65,20,53,75,62,65,73,69
    Target binary value (for "T�rkiye Is Bankasi Gayrettepe Subesi")
    is
    Typ=1 Len=38: 54,ef,bf,bd,72,6b,69,79,65,20,49,73,20,42,61,6e,6b,61,73,69,20,47,61,79,72,65,74,74,65,70,65,20,53,75,62,65,73,69

  • Time-dependent Vendor Master & Handling Special Characters

    Hi,
    I need to extract time-dependent Vendor Master.
    1. The data source for <b>0VENDOR</b> does not have fields to hold the valid date range.
    2. Does the Master data in R/3 for Vendors will hold the valid date range?
    3. The text for <b>0VENDOR</b> provides time-dependent, but how to map the <b>valid from</b> and <b>valid to</b> fields?
    Handling Special Characters:
    We are trying to extract data from Legacy system via DB Connect. The item text field consists of special characters. Of course in BW customization we can specify all the special characters to consider. But the special character we observed is 'square' symbol i.e. 'new line character' in Oracle. We are updating this to an ODS object. When looked at error log, observed that green light for the number of records transferred and updated, but finally when it load into ODS object and activates popping up the error message saying 'could not recognize special character'.
    Please help me getting the 2 issues resolved.
    Thanks in advance.
    Regards,
    Sudhakar.

    Hi Everyone,
    Thanks for inputs on Special characters issue...
    Finally resolved with below piece of code in the start routine:
    DATA: FLAG,
          OFF TYPE I,
          LEN TYPE I VALUE 1,
          ALLOWED_CHAR(95) VALUE
    '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ`~!@#$%^&*()-_=+ ' &
    'abcdefghijklmnopqrstuvwxyz:;<>,.?/|\{}[]"'''.
    CONSTANTS: C_CHAR VALUE '-'.
      LOOP AT DATA_PACKAGE WHERE NOT /BIC/ZI_DESC IS INITIAL .
        DO.
          IF DATA_PACKAGE-/BIC/ZI_DESC CN  ALLOWED_CHAR.
            REPLACE SECTION OFFSET SY-FDPOS LENGTH LEN OF
                    DATA_PACKAGE-/BIC/ZI_DESC WITH C_CHAR.
            FLAG = SPACE.
          ELSE.
            FLAG = 'X'.
          ENDIF.
          IF FLAG = 'X'.
            EXIT.
          ENDIF.
        ENDDO.
        MODIFY DATA_PACKAGE.
      ENDLOOP.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    I have seen the link sent by 'Eugene Khusainov' today. Thought putting my piece of code that may help others...
    Regards,
    Sudhakar.

  • How to save Special Characters in oracle?

    Is there any way to enter special characters such as ºC ? i am using J2EE and Oracle 9 i.
    When i try to enter 2ºC after updating the datbase it is converted to 2ºC when it is displayed in HTML. All special characters are prefixed with Â. Pls suggest any way to use special characters with oracle ..

    This has nothing do to with NLS_LANGUAGE. In general, character set processing depends on NLS_LANG setting (which is an OS setting and not a instance initialization parameter) and database character set. To understand NLS_LANG see OTN NLS_LANG FAQ http://www.oracle.com/technology/tech/globalization/htdocs/nls_lang%20faq.htm.
    However, I think that JDBC is an exception and does not use the character set defined by NLS_LANG. See last answer in following discussion:
    Re: When is NLS_LANG used ?

  • Handling special characters in XML

    Hi,
    I am using Oracle 10g 'XMLType' datatype to store XML files. Before storing I parse the XML document using Java Xerces Parser. If it parses successfuly, then I perform some business rule execution based on XML file which was parsed. So till this stage there is no problems. But when XML file contains some special characters like copy-paste of some description from MS-Word document into XML tags, then Xerces parser will parse such characters with out any exceptions, but while inserting XML document, Oracle database just throws exception saying unable to handle special characters.. So how to avoid such exceptions or silent such exceptions with any specific settings respect to XMLType datatype in 10g DB.
    Please advice!
    Arvind Patil - IN

    Monica--
    In XI 2.0, we've noticed a number of issues processing special characters, primarily caused by the version of JCO that we're running.  It sounds like SAP has spent some time in the past few months focusing on these errors, so make sure you're on the most recent patchlevels of all your middleware components, including any of the middleware libraries that BC uses. In XI, we had to update the 3 files that make up the RFC library and JCO library.  SDM couldn't update the libraries for us -- we had to manually move the files to the right place.
    Escaped XML characters like "&amp;" "&#34;" "&quot;" were fixed as of JCO 2.0.10 (the current patchlevel on AIX/UNIX), the special character "&apos;" is fixed in the next release, JCO 2.0.11, due out in a few weeks (hotfixes are available).  I don't know the equivalent versions on other platforms.  By default, XI 2.0 appears to have shipped with JCO 2.0.5.  I would expect many XI 3.0 users to also be affected.
    This may or may not apply to BC, because I don't know what BC uses to talk to SAP under the covers.
    --Dan King
    Capgemini

  • To Handle Special Characters(Guideu0099 ) in MATMAS IDOC fields

    Need to handle special characters like Guide™, as an attached  superscript in MATMAS02/05 IDOC field . The field name is TDLINE in E1MTXLM segment.
    As a trial run when these special characters are pasted in the TDLINE field, it throws an error that "the input field contains prohibited characters"
    Please let me know if there is any workaround for this.

    hi
    good
    go through these links, i hope these ll help you to solve your problem.
    http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CAGTFADMLO/CAGTFADMLO.pdf
    http://www.erphome.net/wdb/upload/forum14_f_2908.doc
    thanks
    mrutyun^

  • Handle special characters in the attribute name

    Hi,
    I am generating different view element in WD application dynamically. How to handle special characters other than '-/ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'  for the attribute name dynamically?
    Thank you, in advance.
    Trupti

    Going with the obvious response - don't use them?
    if you're using dynamic code, there is no reason (other than debug support) to give your created elements any meaningful name.
    Just generate a GUID for each new element and use that.
    If you need to be able to later search for and update the element a simple lookup table of GUID to reference string should work reasonably well.
    Cheers,
    Chris

  • ### Problem in retrieving special characters with Oracle 9i JDBC drivers

    hi,
    We are having some problem with retrieving special characters like '�' from the database.
    Our application is using JDK1.3.1 with Oracle 9i at the back end(Version: 9.0.1.0.0). We are using oracle 9i thin drivers (classes12.zip) for database interaction.
    To relieve the data from database we are using PreparedStatement in two ways
    1. Creating a preparedstatement from connection object without any parameters and then retrieve the
    data using it. This gives the results in correct format i.e. special characters like '�'
    2. Create the preparedstatement by passing the following parameters.
    i) ResultSet.TYPE_SCROLL_INSENSITIVE
    ii) ResultSet.CONCUR_READ_ONLY
    In this case we are not able to retrieve the special character like '�' correctly. Instead the ResultSet
    returns 'h'
    I think this is the problem with Oracle drivers. Does anyone have any information about the mentioned problem.
    rgds

    I don't know exactly (because I am using JDK 1.4 with ojdbc14.jar where these problems seem to be rare...) but you may consider this:
    1. Add nls_charset12.zip to your classpath to ensure that the encoders are present (may or may not help)
    2. Swith to JDK 1.4, and do this:
    Instead of String s = getString(column)
    use
    byte[] bytes = getBytes(column);
    ByteBuffer bb = ByteBuffer.wrap(bytes); // in package java.nio
    CharBuffer cb = Charset.forname("ISO-8859-x").decode(bb);
    String s = cb.toString();
    The latter method allows you to perform the encoding/decoding manually.
    3. Change the character encoding in the database to unicode upon database setup.
    4. Try playing with NLS parameters (alter session ...)

  • How to handle special characters such as apostrophe, ampersant

    Hello All,
    Tools:
    JSP, JSDK 2
    Oracle 8
    Issue:
    If the user supplies a String value inside a text box which has special characters such as apostrophe, while we try to compare that string with some value in the database, the sql error comes up as the sql string will be broken.
    Example:
    input string--> ABC D'OLL
    sql --> "select * from verndor where vendor_name ='ABC D'OLL' "
    Present solution:
    I am reading each input string & look for such special characters. if so, replaces that character with escape character + that character.
    This solution works.
    Problem:
    If there any more efficient way to handle such character??
    At java level or Database level
    Thanks In advance :)

    Use PreparedStatements

  • Special character: UTF8, Oracle, JDBC

    Hi,
    we have a connection to a Oracle database using JDBC; the tables there are set to UTF8. Unfortunately, some special characters don't appear as they should.
    In Crystal Reports 2008 (with all updates) I already set the "Preferred Viewing Locale" to "Danish", but I still have the wrong characters.
    Where else could I look to troubleshoot this?
    Thanks!

    As a test try connecting using one of the other drivers, ODBC, OLE DB or Native Oracle drivers. If it works then look at the JDBC driver causing the problem.
    Try using your JDBC driver out side of CR and see if it works also to confirm it will work.
    Thank you
    Don

  • How to handle special characters in Apex

    Hi ,
    In my application I have two regions - one is Report Region (Interactive Report) and other one is HTML region with two text items - Empno and name
    My Report has two columns Empno(varchar2) and Ename(varchar2).
    When I click the edit link in the report column, the empno should have a read only EMPNO value and ename is a text field with ENAME value.
    When I run my application I have encountered the following problems :
    1. if my empno has special characters like ' # ', the characters after that is not getting displayed
    2. if my empno has special characters like ',' - the characters after comma is treated as a next texitem value
    Here is my credential ,
    Workspace CTSAN_ORACLE_DB
    Username [email protected]
    Password lakshmi321
    URL : http://apex.oracle.com/pls/apex/f?p=9444:19:4292839314890159:::::
    Plz. suggest me how to rectify the above problems.
    Thanks,
    Anoo..
    Edited by: Anoo on Aug 13, 2010 3:05 AM

    Don't pass data values in URLs. Whilst it is possible to escape values to make them URL- and APEX parameter-safe, it is much better practice to avoid the problem altogether.
    Create a surrogate primary key on the table that is an immutable discrete numeric identifier and only use this as a URL parameter. In target pages/regions, use this PK value to retrieve the required data from the table.

  • How to Handle Special Characters in PI7.1

    Hi Team,
    I need to handle some special characters like <,>,& etc.. from WS Adapter to CRM in PI 7.1.
    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9420 [original link is broken]
    By using the above blog i had implemented the Java Code as
    public void execute(InputStream in, OutputStream out){
    try{
    int read_data;
    while((read_data = in.read()) != -1){
    if (read_data == '&'){
    out.write("&amp;".getBytes());
    }else if (read_data == '>'){
    out.write("&gt;".getBytes());
    }else if (read_data == '<'){
    out.write("&lt;".getBytes());
    }else if (read_data == '/'){
    out.write("&frasl;".getBytes());
    }else if (read_data == '\''){
    out.write("&apos;".getBytes());
    else { out.write(read_data);
    out.flush();
    } catch (Exception e){}
    I had added this class file in Operational Mapping.
    It is working  if we have only one IF condition for & in while
    Any suggestion
    Thanks
    Sriram

    Hi Ramesh,
    Thanks for your inputs, I have tried your code but it is not working. The error message stays the same.
    Dear Stephane,
    To describe the error more, the requirement is the payload coming from source through WS Adapter consists of the special characters <, > , & which are basic sematics of XML syntax. I need PI to process this payload with special characters and successfully transfer it to target CRM system. I have created the Java class with code (ref: Blog 9420) as stated earlier and added this class to my existing Operation Mapping. I am expecting the java mapping to replace the special characters in payload like  < with "&gt;" . So as the case with the other characters >,&,'
    After activaton of my operation mapping, I triggered the test message with Soap UI client and I could able to get a successful mapping only When I put the logic for &ampersand symbol only. However when I am trying to add the logic for > or < or ' the mapping is failing . I am using UTF-8 encoding across the source and PI enviroments.
    Sample SOAP message :
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:abcabca.com">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:MT_ABCDEFG_Req>
         <activity>
              <id/>
              <type>ZEMA</type>
              <actionType>C</actionType>
              <firewall>10000003</firewall>
              <subject>small &gt; &lt; attachment test</subject>
              <location/>
              <startDate>2010-07-08T10:53:31.000Z</startDate>
              <endDate>2010-07-08T10:53:31.000Z</endDate>
              <mainClient>1000319</mainClient>
              <mainContact>1000003</mainContact>
              <isConfidential>false</isConfidential>
              <summary/>
              <fullText>test body  - small.txt</fullText>
              <owner>1000021</owner>
              <from>ABCDEDF</from>
              <sendTo>emailaddress</sendTo>
              <copyTo/>
              <keywords/>
              <referenceId/>
              <createdBy>1000021</createdBy>
              <additionalContacts/>
              <additionalClients/>
              <additionalParticipants/>
              <status>A0008</status>
              <attachments>
                   <fileUrl>20100708110053-XXXXXXXXX</fileUrl>
                   <fileName>small.txt</fileName>
              </attachments>
              <attachments>
                   <fileUrl>20100708110053-XXXXXXXXX</fileUrl>
                   <fileName>EMail 2010-07-08.pdf</fileName>
              </attachments>
         </activity>
          </urn:MT_ABCDEFG_Req>
       </soapenv:Body>
    </soapenv:Envelope>
    Output on the SOAP UI  client for the above request:
    <!--see the documentation-->
    <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
       <SOAP:Body>
          <SOAP:Fault>
             <faultcode>SOAP:Server</faultcode>
             <faultstring>Server Error</faultstring>
             <detail>
                <s:SystemError xmlns:s="http://sap.com/xi/WebService/xi2.0">
                   <context>XIAdapter</context>
                   <code>ADAPTER.JAVA_EXCEPTION</code>
                   <text>com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.engine.interfaces.messaging.api.exception.MessagingException: XIServer:NO_MAPPINGPROGRAM_FOUND:
         at com.sap.aii.adapter.soap.ejb.XISOAPAdapterBean.process(XISOAPAdapterBean.java:1160)
         at sun.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(
    What do you think where I am doing the wrong?
    Sriram

  • How to handle special characters in NWDI

    Dear All
    I am trying to update the Description from JSP form. Through JCO we are calling the RFC of ABAP. We are passing these description from Java to RFC of ABAP and this RFC update the text in Database.
    We have noticed that if there is some special character in description like as : š or ž, complete description is not getting updated in to the SAP database.
    Can anyone help me how to handle these special characters in Java. There may be N number of special characters. We want to generalize it. We want to replace these characters by s and z respectively.
    For example : We want to update this description.
    APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 riješen je cleaning procedurom, te je i kroz CSR odgovoreno da trap korekcija N01TCADG-0052 u bloku UPDC više nije potrebna, te se može izbaciti (AP143).
    Uspješno su završene HR17/CN-A3 FOA-e na tranzitnom nivou, te slijedi roll-out u dva termina 12/13.04 i 19/20.04. ETK je na sastanku isporu&#269;io SW, te ALEX i mini PLEX za sve objekte.
    AP147. Poslati finalnu dokumentaciju za uvo&#273;enje paketa (implementacijsku instrukciju i sve popratne datoteke).
    WHile updated text is as follows :
    APPLERR H'4301 H'FA03 H'254C na Zagreb TC4 rije
    N01TCADG-0052 u bloku UPDC vi
    Uspje
    sastanku isporu
    AP147. Poslati finalnu dokumentaciju za uvo
    Regards
    Bhavishya

    Hi Bhavishya,
    Apparently your SAP database isn't configured to support Unicode. That would be the first solution to your problem, but I can imagine it's a bit drastic to convert your DB.
    A second solution would be to encode the input description to ASCII before storing it in the database. When reading from the database, decode again to Unicode. This way, no information is lost. A suitable encoding would be Base64. e.g.
    String description = "šunday žebra";
    String descriptionBase64 = new sun.misc.BASE64Encoder().encode(
      description.getBytes("UTF-8")); // ""
    // store descriptionBase64 in the DB
    // later, when reading descriptionBase64 from the DB
    String description2 = new String(
      new sun.misc.BASE64Decoder().decodeBuffer(descriptionBase64), "UTF-8");
    Instead of using Sun's implementation, a better alternative is to use the open source implementation
    org.apache.commons.codec.binary.Base64 from Commons Codec . 
    The 3rd approach is indeed to normalize the description by replacing all special characters with their ASCII equivalent. A rather easy solution is as follows:
    String description = "šunday žebra";
    String descriptionNormalized = sun.text.Normalizer.normalize(
      description, sun.text.Normalizer.DECOMP, 0).replaceAll(
      "[^p{ASCII}]", "");
    sun.text.Normalizer decomposes the string, e.g. "éàî" becomes "e´a`i^", after which non-ASCII characters are being removed using a regular expression.Again, note that it's usually a bad idea to use sun.* packages, see note about sun.* packages. The above code only works with J2SE 1.4 and J2SE 5.0, but it breaks in J2SE 6.0 (where
    java.text.Normalizer became part of the public API ;-). A good open source implementation can be found here: ICU4J (com.ibm.icu.text.Normalizer). 
    Kind regards,
    /Sigiswald

  • Error while handling special characters ( and &) in Sender File adapter

    Dear All,
    Scenario: Third Party System --> (File adapter) SAP PI 7.1 (SP05) --> (Proxy) ECC
    We are receiving CSV file and no mapping is required in PI as all the processing is being done by third party tool. But we are receiving special characters like ',",>,< and & in the csv file.
    When we are using File Type as TEXT and File Encoding as ISO-8859-1 than we are getting error. We changed File Type to BINARY and than we are able to handle ',",> but having issue in handling < and &.
    Any idea how we can handle it.
    Please note trhere is no Mapping in SAP PI so cannot uise Java mapping.
    Thanks a lot
    Chanakya

    Hey,
    You can add ABAP Script in Receiver Proxy for eliminating or replacing with NULL or empty. Since you dont have mapping for formatting these kind of junks you can follow the above approach.
    Else, you can remove the junks at OS level while running a small script and make it available to PI.
    Or else, you need to create mapping for sender and recevier structure though it is same, then you add a very simple UDF for fine tune.
    Use this UDF
    Here a is the input value.
    String b = "";
    b = a.replaceAll(",", "0");
    b = a.replaceAll("@", "0");
    Like all the special characters you can take and replace with zero.
    return b;
    Thanx
    Pothana

  • Reading and writing Special Characters to Oracle DB

    Hi All,
    I need to insert data from CSV to Oracle DB and then use the same data for creating XML file in UTF-8 format.
    I have few fields in the CSV file which has � and � special characters. I'm able to read � and write in UTF-8 , but the same procedure is resulting in some other ascii character for �.
    While reading data from CSV file :
    Reader l_fileReader = new InputStreamReader(p_in,"ISO-8859-1");
    Can anyone help me.
    Thanks,
    Ramki.

    Does anyone has some pointers or clues?

Maybe you are looking for

  • No automatic incidental charges for Purchase Order

    Hi All Please help us obtain the solution. We want that there will be no automatic incidental charges for our Purchase Order but only condition type will be displayed. Situation: 1. Info record already exists 2. Already changed the config for OMFI. I

  • FPGA to Real Time using DMA to Host using Network Stream

    Hi All, So I am working on a project where I am monitoring various characteristics of a modified diesel engine being driven by a dynamometer. I am trying to log different pressures, temperatures, and engine speed. It basically breaks down into two st

  • Can you turn a single 18-page Indesign file into 18 individual Indesign files?

    I am working in CS5 and am laying out a newspaper in Indesign. I would like to save the 18 page file into 18 separate files (1 page per file) so other people can work on different pages. Is this possible? Exporting as a pdf and extracting doesn't qui

  • 3D TV. Samsung, LG?

    I'm going to buy 3D TV. Samsung, LG which brand is better?

  • Problems with output of a bpel process

    Hi, I have a process with the following schema: <schema attributeFormDefault="qualified"      elementFormDefault="qualified"      targetNamespace="http://xmlns.oracle.com/BPELProcess1"      xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://x