Reading a string containing special character from a result set

My Code....
PrintStream p = new PrintStream(fout);
if (connection == null)
connection = getConnection();
CallableStatement proc = connection.prepareCall("{call testing_read()}");
rs = proc.executeQuery();
while ( rs.next() )
String page2 = rs.getString(1);
System.out.println(page2);
rs.getString(1); is a string value eg. 'Rebekah \n Govender' that is being set in a stored procedure.
The output of my program is :'Rebekah \n Govender' , i need for it to read the special characters, and produce this output :
Rebekah
Govender
Without using a result set , it works fine.
eg.
String page2 = 'Rebekah \n Govender'
System.out.println(page2);
Will give an output of :
Rebekah
Govender
I need to read values from the results set, pls help me someone....
Please help....

String page2 = rs.getString(1).replace("\\n", "\n"); When you include source code in your posts, please enclose it in CODE tags. There's a button for that above the input textarea.
ThE-MaRaC wrote:
Hi,
you can try something like this:
import java.io.UnsupportedEncodingException;;
*  Main class, manages the complete game
public class Main {
public static void main(String[] args) {
String page2 = "Rebekah \n Govender";
try {
page2 = new String(page2.getBytes("ISO-8859-1"), "ETF-8");
} catch (UnsupportedEncodingException e) {}
System.out.println(page2);
}Regards,
Hercog MarioThat is a disgusting hack which you shouldn't be recommending to anyone, and it's totally irrelevant here anyway. Also, as written, it does absolutely nothing because you misspelled "UTF-8" and you swallowed the exception that would have told you so.

Similar Messages

  • How to read text file contain chinese character ?

    Hi XI Expert,
    I have scenario to read text file contain Chinese Character using sender file adapter. but every i was check from sxmb_moni all the chinese character looks different. and also the target file also i has changes.
    Please advise me how to maintaine the chinese character in PI 7.0 SP17.
    Thank You and Best Regards
    Fernand

    Hi,
    Refer these threads..
    Receiver file adapter corrupting characters
    Problem in converting special characters in input text file
    Here is one more useful guide..
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/502991a2-45d9-2910-d99f-8aba5d79fb42
    Regards,
    Sarvesh
    Edited by: Sarvesh Singh on Nov 17, 2008 3:47 PM

  • Removing Duplicate records from this result set

    Here is a challenge question that I was playing with one my free time during work.
    I assume that you have the HR sample database somewhere around (hopefully not in production).
    Let us say that you want to get employees from the employees table whose last name is similar to some other employee last name.
    The easiest way is to join the two tables with a join condition that checks for the last name and the employee id. Here is what I came up with.
    select e1.last_name a , e1.first_name b, e2.last_name c, e2.first_name d
    from employees e1 join employees e2
    on ( e1.last_name = e2.last_name and e1.employee_id <> e2.employee_id)
    order by a;
    The above query returns 10 rows. The first and second are essentially the same. The same applies of 3&4, 5&6, 7&8, and 9&10. The question is: is there any way that allow me to get rid of the duplicate rows using sql only from the result set of this query. I sat on it for 15 minutes and I could not figure it out. I will try looking at again after my work is over.

    Example:
    SQL> column a format a10
    SQL> column b format a10
    SQL> column c format a10
    SQL> column d format a10
    SQL>
    SQL>
    SQL> select e1.last_name a , e1.first_name b, e2.last_name c, e2.first_name d
      2  from employees e1 join employees e2
      3  on ( e1.last_name = e2.last_name and e1.employee_id != e2.employee_id)
      4  where e1.employee_id < e2.employee_id
      5  order by a;
    A          B          C          D
    Cambrault  Gerald     Cambrault  Nanette
    Grant      Kimberely  Grant      Douglas
    King       Steven     King       Janette
    Smith      Lindsey    Smith      William
    Taylor     Jonathon   Taylor     Winston
    SQL>

  • Detect special character from a String

    Hello guys,
    Some of the files in unix box contain special characters . I need to strip these special character in the filename to underscore. however, I do not want to strip off special character like _ - ^ . @
    Pattern escaper = Pattern.compile("([^a-zA-z0-9_-^.@])");
    I couldn't strip off the caret. Appreciate any advice please. Thanks in advance!
    Cheers,
    Mark

    Hi Alice,
    I tried your suggestion:
         public static void main(String[] args) throws IOException {
              rename(args[0], args[0].replaceAll("[^a-zA-Z0-9\\\\/:@._^-]","_"));
         public static void rename(String from, String to) throws IOException{
              // File (or directory) with old name
              File file1 = new File(from);
              // File (or directory) with new name
              File file2 = new File(to);
              // Rename file (or directory)
              boolean success = file1.renameTo(file2);
              if (!success) { // File was not successfully renamed
                   System.out.println("failed to rename : " + file1);
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1~2.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1^2.txt
    failed to rename : C:\Apps\mud\12.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\[email protected]
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3mn.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3mn.txt
    failed to rename : C:\Apps\mud\1@2$-_3mn.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'n.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'^n.txt
    failed to rename : C:\Apps\mud\1@2$-_3m'n.txt
    C:\workspace\TestOnly\bin>java -cp . com.test.TestClass C:\Apps\mud\1@2$-_3m'^n.txtbut however, whenever I put in a caret in the filename, it always failed to rename. Appreciate your further advice please. thanks in advance!
    Cheers,
    Mark

  • How do I find file names containing special character

    hi all
    I need your help with a code that deals with finding file names containing special characters like * / \ : ? " |
    the reason is I am doing a project that transfer files and folders from Mac to Windows. But names containing above characters cant be moved to windows.
    the part of the code I write is like this
    set illegal_syntax to paragraphs of (do shell script "find " & quoted form of POSIX path of oneFolder & " -name '*'")
    if (illegal_syntax is not equal to {""}) then
    repeat with each_record in illegal_syntax
    do shell script "/usr/bin/ditto -c -k -rsrc --keepParent " & quoted form of each_record & space & quoted form of (each_record & ".zip")
    end repeat
    end if
    First of all that '' will gives me an error.
    Second, what i tried to do is once the file/folder is found, zip it at current location. But the problem is how can I zip it without the special character? or should I just give it a name, like "originalfile.zip";?
    Last, or maybe you have better idea to deal with this situation? BTW, I can not rename or delete the file/folder because customer won't allow me to do it.

    The backslash is used to escape characters in AppleScript, so if you want to use it in a string you need to escape the escape character, for example "\\*".
    You could set the name of the archive by replacing the illegal character with another one, such as an underscore:
    <pre title="this text can be pasted into the Script Editor" style="font-family: Monaco, 'Courier New', Courier, monospace; font-size: 10px; padding: 5px; border: 1px solid #000000; width: 720px; color: #000000; background-color: #FFDDFF; overflow: auto">set each_record to "some*file*name" -- example
    set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "*"}
    set the ItemList to text items of each_record
    set AppleScript's text item delimiters to "_"
    set each_record to the ItemList as text
    set AppleScript's text item delimiters to TempTID
    log each_record --> some_file_name
    </pre>

  • How to insert special character from Oracle form builder 10g

    Dear all,
    I need help. how to insert special character like 'Superscript or Subscript ' from oracle form builder 10g. I had try in Oracle form builder 6i with press ALT+ASCII code in the text item and it work, but in the oracle form builder 10g this method doesn't work... would you like to help me...somebody please...
    Best Regard,
    Dedy P.T.

    What do you mean by insert ... from Forms Builder? Do you mean you want to add it as text in a string of pl/sql code or as part of boiler plate text (label) or a value on the Property Palette?
    For special characters you would need set NLS_LANG to something that would support the characters you want to use. For the Builder to see the change, you would need to set NLS_LANG to something like:
    NLS_LANG=AMERICAN_AMERICA.UTF8
    This can be done in the Windows Registry or system. As I mentioned, this will only apply to the Builder and will have nothing to do with a running form. For running forms you would need to set this in default.env. As for things like super and sub scripts, these are font formats and not necessarily characters. For the most part, I don't believe these are supported in Forms.

  • String contains special chars

    Hi there,
    If given string contains a special character in the first position..i need to delete the character from the string.
    please suggest a way..

    It's clunky, but try this:
    To replace special character with space.
    data:  w_val type string.
    move old_string+0(1) to w_val.
    replace first occurance of w_val in old_string with space.
    OR
    To remove it entirely
    shift old_string by 1 places left.    " Shifts string to left and drops off characters to left.
    Steve

  • Quick string question finding if a string contains a character

    hello peeps
    is there a quick way of checking if a string contains a specific character
    e.g.
    myString="test:test";
    myString.contains(":");
    would be true
    any ideas on a quick way of doing it

    is there a contains() method in 1.4.2? i couldnt see
    it in the docsNo there isn't. But the 1.5 has a contains(CharSequence s) method.

  • Parsing xml that contains special character

    this is my xml file.
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <grid_assessment>
         <chart>
              <range>5</range>
              <sharing_charging>
                   <score>3</score>
                   <label><![CDATA[SHARING &#38; CHARGING POLICIES]]></label>
    this is my java code.
              SAXParser parser = new SAXParser();
              parser.setContentHandler(this);
              parser.setErrorHandler(this);
              try
                   fis = new FileInputStream(xmlFile);
              catch(IOException ioe)
                   System.out.println( ioe.getMessage() );
              InputSource inputSource = new InputSource((InputStream)fis);
              try
                   parser.parse(inputSource);
              catch(SAXException saxe)
                   System.out.println( saxe.getMessage() );
              catch(IOException ioe)
                   System.out.println(ioe.getMessage());
    when i parse the xml file, i got an error message like this.
    org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.Stopping after fatal error: The entity name must immediately follow the '&' in the entity reference.
    is there anybody who knows how to parse the xml file that contais special character?
    i tried "&#38;" instead of "&". but it didn't work...
    please help...
    thanks in advance...

    this is my java code.
              SAXParser parser = new SAXParser();If that is javax.xml.parsers.SAXParser then your code won't compile; i suspect you might be using some non-standard parser?
              parser.setContentHandler(this);
              parser.setErrorHandler(this);These methods are deprecated.
    when i parse the xml file, i got an error message like this.
    org.xml.sax.SAXParseException: The entity name must
    immediately follow the '&' in the entity
    reference.Stopping after fatal error: The entity name
    must immediately follow the '&' in the entity
    reference.I don't; maybe it's your parser. What parser are you using, and what version?
    is there anybody who knows how to parse the xml file
    that contais special character?There is nothing more you need to do; the codeimport javax.xml.parsers.*;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.*;
    import java.io.*;
    public class CeasarKim1Parser extends DefaultHandler {
      public static void main (String[] args) {
        try {
          SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
          FileInputStream fis = null;
          fis = new FileInputStream(args[0]);
          InputSource inputSource = new InputSource((InputStream)fis);
          parser.parse(inputSource, new CeasarKim1Parser () );
        } catch(SAXException saxe) {
          saxe.printStackTrace();
        } catch(IOException ioe) {
          ioe.printStackTrace();
        } catch (ParserConfigurationException pce) {
          pce.printStackTrace();
      public void characters(char[] ch, int start, int length) {
        System.out.println(new String(ch, start, length));
    // similar implementations of the other content handler methods
    }which is basically a compilable and non-deprecated version of yours, with the file<?xml version="1.0" encoding="ISO-8859-1" ?>
    <grid_assessment>
      <chart>
        <range>5</range>
        <sharing_charging>
          <score>3</score>
          <label><![CDATA[SHARING & CHARGING POLICIES]]></label>
        </sharing_charging>
      </chart>
    </grid_assessment>does not generate any exceptions and parses the CDATA section correctly. That is using 1.4.1 and the default org.apache.crimson.jaxp.SAXParserImpl parser.
    Pete

  • How to discard the special character from field-Table.

    Hi
    In my data i am having a lot of SPECIAL CHARACTER also involved, I want to display only the consumer name (PURELY), is there any method/function module to discard the special character and display only the A-Z character as stored in DB.
    Gaurav

    if itab-field CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    or
    if itab-field CP 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
    then do ur else calculation.
    else.
    delete itab.
    Edited by: tahir naqqash on Feb 17, 2009 4:27 PM
    Edited by: tahir naqqash on Feb 17, 2009 5:21 PM

  • How to replace string containing special characters by another string

    Hi all,
    I have to Search for a pattern and replace it by a substitute pattern [Eg: Replace methodOrig (a,b) with  SessTime = getSessionParameter(time);  methodNew(a,b,SessTime) ] in files.
    i tried this using replace(),but it din't work since string1 contains special characters.
    can anyone help me asap.
    thanks in advance.

    Double-post: http://forum.java.sun.com/thread.jspa?threadID=599211&tstart=0

  • Counting a Special Character from a String

    Hello,
    I have a String let say 'ABC-X', 'ABC-X-Y' ....
    so how can we find the count/No. of Hypen('-') .. in a string....

    I have a String let say 'ABC-X', 'ABC-X-Y' ....
    so how can we find the count/No. of Hypen('-') .. in a string....
    SQL> var str varchar2(20);
    SQL> exec :str := 'ABC-X-Y';
    PL/SQL procedure successfully completed.
    SQL> select length(:str) - nvl(length(replace(:str,'-')),0) from dual;
    LENGTH(:STR)-NVL(LENGTH(REPLACE(:STR,'-')),0)
                                                2
    SQL>

  • Request for an sql to scan for a special character from the tables

    Hi Gurus
    request for an sql statement for finding the character (and replace with a single byte character ) which occupy
    multibytes(in a unidata char set database) the database which is yet to be migrated to unidata(multibyte) database
    any kind of help is highly apprciated
    Thanks in advance

    Query below will find all bulti-byte characters in string column:
    select  string_column,
            substr(string_column,column_value,1)
      from  some_table,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= length(string_column)
                       as sys.OdciNumberList
      where lengthb(substr(string_column,column_value,1)) > 1
      order by string_column,
               column_value
    /SY.

  • Remove Special Character "/" from file name

    I'm trying to upload a PDF located on my desktop to a server that won't accept special characters, and the mac path is by default ~/desktop/file ... all those forward slashes read as "special characters" and the file is rejected. I moved the file as high as I could, out of the user folder and onto the HD, but it still contains a "/" as the initial character even there.
    How do I get rid of the "/" at the beginning of the file name? Thanks...

    You can't; every location where a file can be placed on a disk available to Mac OS X contains a / in the path. Contact the server's operators or move the file to a computer running another OS.
    (42358)

  • How to select special character from OLE DB source in SSIS?- Truncation error.

    Hi,
    I have to pull data from one Oracle table and for that I am using OLE DB source in SSIS. In OLE DB source I write query like, 
    SELECT     DESCRIPTION
    FROM         INV.ITEMS_LOCATION
    and packages failed with truncation error. When I redirect this column for truncation I see below result in data viewer,
    ErrorCode
    ErrorColumn
    DESCRIPTION
    ErrorCode - Description
    -1071607693
    8884
    HC Afd Set__ZDV?N07-03075
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 4DO1-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 3DO3-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 4DP01-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel DBDS-10-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Filter TXW?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__ZDV?N07-03075
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 4DO1-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 3DO3-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel 4DP01-?
    The data was truncated.  
    -1071607693
    8884
    HC Afd Set__Ventiel DBDS-10-?
    The data was truncated.  
    I don't how to put this value in table. I use code page 65001(UTF-8) and 1252, but it is not working, and giving error like 
    [OLE DB Source [16]] Error: Column "DESCRIPTION" cannot convert between unicode and non-unicode string data types.
    Data Type of 'DESCRIPTION' source(External) column is varchar(240) and same- varchar(240) I used for output column and in my table's data type. I also tried with varchar(1000) for output column in OLE DB Source but same truncation error.
    I also tried to convert DESCRIPTION into navachar using below cast function but got error.
    SELECT   -- TO_NVARCHAR(DESCRIPTION) AS DESCRIPTION,
    --CAST(DESCRIPTION AS NVARCHAR(240)) DESCRIPTION, 
    Please let me know how to load this value in table. Thank you in advance.
    Vicky

    Thanks ArthurZ for reply.
    But for testing I am just using OLEDB source and OLE DB destination only in my ssis package.
    For Column "DESCRIPTION", data type is VARCHAR(240)
    in external column, output column and target table column.
    And I tried to cast source column into nvarchar and also set target column to nvarchar to handle this kind of special characters but package is failing,
    I also tried TO_NCHAR(DESCRIPTION)
    in my source query to convert it to nvarchar but error is something like character mismatch.
    Vicky

Maybe you are looking for