How is ResultSet.getString() SUPPOSED to return BINARY types?

Hello All:
I got a legacy code to support. The code uses ResultSet.getString() to retrieve BINARY data. ORACLE JDBC driver converts binary data to their hexadecimal representation. It also behaves "correctly" in this sense when I use setString() on prepared statement for BINARY field: it converts valid hexadecimal strings to binary data and rejects strings which contains non-HEX digit characters with SQLException (btw if I give it an odd number of hexadecimal digits, it adds a zero digits FROM THE LEFT e.g. DDDDDDDDDDDDDDDDDDDDDDD becomes 0DDDDDDDDDDDDDDDDDDDDDDD).
My question is: is all this behavior documented somewhere in JDBC specification and if not how other databases and drives behave on this matter. The code will be possibly used with other databases and I want to know if I can expect some definite behaviour or this is all implementation-specific? I found in JDBC specs that getString() can be used for BINARY data -- but not what it is supposed to return? Even Oracle JDBC documentation does not specify the behavior I discovered -- it just works like that but can I be sure it will be preserved in further versions? Should we raise an issue with Sun to clarify the JDBC specs?
Any ideas/references? Please share your experience with different databases/drivers. Mine is Oracle 8.0.5.1.0, JDBC driver version is 9.0.1.0.0.
Pavel

You can download the JDBC docs from the sun site. I didn't find anything in it which documented the behavior you indicated.

Similar Messages

  • Transfer of stock from Returns stock type to Unrestricted/Blocked

    Hi,Friends
    How to transfer of stock from Returns stock type to Unrestricted/Blocked
    what movement type will trigger by transfering this stock,
    Thanks & Regards
    Krishna

    Hi,
    use MB1B Mvt Type 453 returns to unrestricted
    Unrestriced to Blocked stock use - 344
    Thanks & Regards,
    kiran

  • Column exist but ResultSet.getString(String) return invalid column name

    With oracle 7 db the ResultSet.getString(String) works fine but after the upgrade to oracle 8 db it return invalid column name. ResultSet.getString(int) method works fine.
    Is this a bug in the driver?
    Thanks
    -Reda

    Yes I'm 100 % sure that the columns exist.
    -RedaWell then maybe it's a bug in the Oracle driver. Lord knows it wouldn't be the first time that's happened.

  • ResultSet.getString(String) doesn't return the right text from database

    Hi everybody,
    I'm trying to read some text in Portuguese from a MS-Access database, but the special characters for Portuguese aren't correctly translated by ResultSet.getString(String).
    Here's my piece of code:
    private static void fetchEquipamentoEstabelecimento()
    try
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(
    " SELECT Eqp.NumSerie, Eqp.Estabelecimento, Estab.Nome, Estab.Cidade, Eqp.Data, Eqp.LPN " +
    " FROM Equipamento Eqp, Estabelecimento Estab " +
    " WHERE TabPreco = 23 " +
              " AND Eqp.Estabelecimento = Estab.Estabelecimento " +
    "ORDER BY NumSerie DESC");
    while(rs.next())
    String nome = rs.getString("Nome");
    System.out.println(rs.getLong("NumSerie")      + " " +
                             rs.getDate("Data")           + " " +
                             rs.getString("LPN")           + " " +
                             nome                              + " " +
                             rs.getString("Cidade"));
    stmt.close();
    catch(SQLException ex)
    printSQLException("fetchEquipamentoEstabelecimento()", ex);
    The output of this piece of code is 1 record joined from tables Equipamento and Estabelecimento:
    111222333 2001-12-15 JHK Pal<X>cio Cristal Guarda
    where the <X> is the greek letter beta. I was expecting a
    portuguese character which is an a with an accent: � (I hope the character was correctly displayed for you)
    I tried replacing
    String nome = rs.getString("Nome");
    with
    String nome = new String(rs.getString("Nome").getBytes(),codepage);
    with codepage="Cp860" (MS-DOS Portuguese)
    and codepage="Cp037" (USA, Canada (Bilingual, French), Netherlands, Portugal, Brazil, Australia)
    but other strange characters were displayed instead of the a with an accent.
    In the MS-Access table Estabelecimento, the column Nome has a Data Type of Text.
    I'm using:
    - JDK 1.2.2
    - MS Access 2000 (in Windows 2000)
    MS Access 97 (in Windows NT 4.0).
    Any help is deeply apreciated.

    Hi!
    When you establish connection to database, try explicitly give instructions about what encoding use your DB, e.g.:
    // connection properties
    Properties connInfo = new Properties();
    connInfo.put("user", username);
    connInfo.put("password", password);
    connInfo.put("charSet", "Cp1251"); // enter your codepage!!!
    // getconnection
    Connection db = DriverManager.getConnection(dataurl, connInfo);

  • How to get number of rows return in SELECT query

    i'm very new in java, i have a question:
    - How to get number of rows return in SELECT query?
    (i use SQL Server 2000 Driver for JDBC and everything are done, i only want to know problems above)
    Thanks.

    make the result set scroll insensitve, do rs.last(), get the row num, and call rs.beforeFirst(), then you can process the result set like you currently do.
             String sql = "select * from testing";
             PreparedStatement ps =
              con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
             ResultSet rs = ps.executeQuery();
             rs.last();
             System.out.println("Row count = " + rs.getRow());
             rs.beforeFirst();~Tim
    NOTE: Ugly, but does the trick.

  • A bug in the ResultSet.getString method?

    Hi,
    I am using a 8.1.6 database with UTF8 character set on a Win2000 machine. I've inserted some Hebrew characters into a table, and have been able to read them back properly using SQL+.
    However, when I try to retrieve these values from a simple Java program using the resultSet.getString method (via Oracle JDBC driver 8.1.6) I always get the '?' character for every Hebrew character (English characters work fine). However, if I call the 'getBytes' method of the result set, and create a new String instance from that data, it works fine - help needed!
    Thanks...
    null

    However, if I call the 'getBytes' method of the result set, and create a new String instance from that data, it works fine - help needed!Thanks...
    Please show me how to using 'getBytes' method of the result set and create a new string instance from THAT DATA, because this way doesn't work for me. I am converting ZHT16DBT to Unicode, and all I got is ?????.
    Please help me if you have any idea. THANKS
    null

  • ResultSet.getString(int) sometimes slow

    I'm working on an app that I'm attempting to optimize using JProfiler. In the course of inspecting how the time is being devided up, I noticed that there is one place in the code where ResultSet.getString(int) is taking much longer than it does in other areas. Usually, it averages anywhere from almost 0 ms to 0.01 ms per call. However, at one specific area, it's averaged anywhere from 7 to 45 ms per call. I can't find anything that sets it apart from any other calls to getResultSet() -- it happens to be averaged over several hundred rows, whereas the other, quicker calls are occurring when there's anywhere from 1 to tens of thousands of rows, so I can't see how the amount of data would have that affect. The result set is being pulled back along with several others from a single statement execution that has several queries, so they should all have the same fetch size. Does anyone have any ideas on what could cause a call to getString(int) at one specific place in the code to be 3-4 orders of magnitude slower than the others?
    Thanks for any help...

    I think you'd have to examine more of what is going on internally in the result set.
    As you mentioned fetch size could be something. It could be the particular type of column for which you are calling getString on.
    It could be a lot of things. There isn't really any answer for this other than to look at what your particular Result Set implementation is actually doing.

  • OCCI ResultSet- getString Linux problem

    Hello,
    On forum I found how the solve problem for OCCI programm witch using MSVC++. May be anybody known how to correct compile and linking OCCI demo on Linux? The demos crashed at ResultSet->getString().

    It is my fault. I use Fedore Core 4 and gcc4.0. By default it linking with libstdc++.6.so, but when I linkint direct with libstdc++.5.so it OK.
    Thank you for support!

  • How to separate enter GR and return in invoice verification

    Hi: guys
    I have completed GR for purchase order, and then, vendor send me invoice. however, during invoice check, warehouse return goods to this vendor. so I just want enter GR item excluding the new return item. but sap system automatically propose total Qtys/amounts. I cann't manually change Qtys/amounts.
    everybody can tell me how to separate enter GR and return in invoice verification.
    someday suggest me use return PO and 161 movetype to deal with this problem. however, I not think this is a good solution.
    thank you
    Henry

    well the main point of u r problem is that u r not able to change the qyantity /value in invoice
    but system should allow u to change the quantity and vlaue as per standard sap settings
    i think u r user profile is not authorized to do so.........chek the authorization for miro
    u can aslo ue invoice reduction option in miro
    suppose u r vendor invoice u for 100 pc but u have recived only 89 pc as 20 pc u have already returned then u can use invoice reduction option to change the quantity and value and in this case sytem will genrate the credit memo and invoice
    100 pc invoice
    20 pc credit memo
    and ultiamtely u have posted 80 pc invoice
    if any thing not clear then let me know

  • How to extend  breadth first Search for Binary Tree to any kind of Tree??

    Dear Friends,
    I am thinking a problem, How to extend breadth first Search for Binary Tree to any kind of Tree?? ie each node has more than 2 leaves such as 1, 2,3,4 or any,
    I have following code to successfully apply for breadth first Search in Binary Tree as follows,
    package a.border;
    import java.util.ArrayList;
    import java.util.LinkedList;
    public class Tree
        int root;
        Tree left;
        Tree right;
        static ArrayList<Integer> list = new ArrayList<Integer>();
        static ArrayList<Tree> treeList = new ArrayList<Tree>();
        private static LinkedList<Tree> queue = new LinkedList<Tree>();
         * @param root root value
         * @param left left node
         * @param right right node
        public Tree(int root, Tree left, Tree right)
            this.root = root;
            this.left = left;
            this.right = right;
        /** Creates a new instance of Tree
         * You really should know what this does...
         * @param root
        public Tree(int root)
            this.root = root;
            this.left = null;
            this.right = null;
         * Simply runs a basic left then right traversal.
        public void basicTraversal()
            //Check if we can go left
            if (left != null)
                left.basicTraversal();
            //Add the root
            list.add(root);
            //Check if we can go right
            if (right != null)
                right.basicTraversal();
        public ArrayList<Integer> getBreadthTraversal(ArrayList<Integer> list)
            //Add the root to the arraylist, we know it is always the first entry.
            list.add(root);
            //Basically we add the first set of nodes into the queue for
            //traversing.
            //Query if left exists
            if (left != null)
                //Then add the node into the tree for traversing later
                queue.add(left);
            //Same for right
            if (right != null)
                queue.add(right);
            //Then we call the traverse method to do the rest of the work
            return traverse(list);
        private ArrayList<Integer> traverse(ArrayList<Integer> list)
            //Keep traversing until we run out of people
            while (!queue.isEmpty())
                Tree p = queue.remove();
                //Check if it has any subnodes
                if (p.left != null)
                    //Add the subnode to the back of the queue
                    queue.add(p.left);
                //Same for left
                if (p.right != null)
                    //Same here, no queue jumping!
                    queue.add(p.right);
                //Append to the ArrayList
                list.add(p.root);
            //And return
            return list;
         * Makes a tree and runs some operations
         * @param args
        public static void main(String[] args)
             *                             4
             *          t =           2       6
             *                      1   3    5   7
            Tree leaf6 = new Tree(1);
            Tree leaf7 = new Tree(3);
            Tree leaf8 = new Tree(5);
            Tree leaf9 = new Tree(7);
            Tree t4 = new Tree(2, leaf6, leaf7);
            Tree t5 = new Tree(6, leaf8, leaf9);
            Tree t = new Tree(4, t4, t5);
            t.basicTraversal();
            System.out.println("Here is basicTraversal ="+list.toString());
            list.clear();
            t.getBreadthTraversal(list);
            System.out.println("getBreadthTraversal= " +list.toString());
            list.clear();
        }Can Guru help how to update to any kind of tree??
    here this code is for the tree like:
             *                             4
             *          t =           2       6
             *                      1   3    5   7
             */But i hope the new code can handle tree like:
             *                             4
             *                           /   | \
             *                          /     |   \
             *          t =            2     8   6
             *                        / |  \    |    /| \
             *                      1 11  3 9   5 10  7
             */Thanks

    sunnymanman wrote:
    Dear Friends,
    I am thinking a problem, How to extend breadth first Search for Binary Tree to any kind of Tree?? ...The answer is interfaces.
    What do all trees have in common? And what do all nodes in trees have in common?
    At least these things:
    interface Tree<T> {
        Node<T> getRoot();
    interface Node<T> {
        T getData();
        List<Node<T>> getChildren();
    }Now write concrete classes implementing these interfaces. Let's start with a binary tree (nodes should have comparable items) and an n-tree:
    class BinaryTree<T extends Comparable<T>> implements Tree<T> {
        protected BTNode<T> root;
        public Node<T> getRoot() {
            return root;
    class BTNode<T> implements Node<T> {
        private T data;
        private Node<T> left, right;
        public List<Node<T>> getChildren() {
            List<Node<T>> children = new ArrayList<Node<T>>();
            children.add(left);
            children.add(right);
            return children;
        public T getData() {
            return data;
    class NTree<T> implements Tree<T> {
        private NTNode<T> root;
        public Node<T> getRoot() {
            return root;
    class NTNode<T> implements Node<T> {
        private T data;
        private List<Node<T>> children;
        public List<Node<T>> getChildren() {
            return children;
        public T getData() {
            return data;
    }Now with these classes, you can wite a more generic traversal class. Of course, every traversal class (breath first, depth first) will also have something in common: they return a "path" of nodes (if the 'goal' node/data is found). So, you can write an interface like this:
    interface Traverser<T> {
        List<Node<T>> traverse(T goal, Tree<T> tree);
    }And finally write an implementation for it:
    class BreathFirst<T> implements Traverser<T> {
        public List<Node<T>> traverse(T goal, Tree<T> tree) {
            Node<T> start = tree.getRoot();
            List<Node<T>> children = start.getChildren();
            // your algorithm here
            return null; // return your traversal
    }... which can be used to traverse any tree! Here's a small demo of how to use it:
    public class Test {
        public static void main(String[] args) {
            Tree<Integer> binTree = new BinaryTree<Integer>();
            // populate your binTree
            Tree<Integer> nTree = new NTree<Integer>();
            // populate your nTree
            Traverser<Integer> bfTraverser = new BreathFirst<Integer>();
            // Look for integer 6 in binTree
            System.out.println("bTree bfTraversal -> "+bfTraverser.traverse(6, binTree));
            // Look for integer 6 in nTree
            System.out.println("bTree bfTraversal -> "+bfTraverser.traverse(6, nTree));
    }Good luck!

  • Data truncation when using resultset.getString() to a char type field

    In my table ,there is a char type field,such as a char(4) field, for multilanguage use,I put two "double-byte" character in it,
    when I using resultset.getString() to this char type field,I can't get the right result,one char was truncated, so I only get three char, for "double-byte" it 's error code
    this only happen on IBM JVM on AIX 5 , when I use oracle jdbc on windows hotspot vm , it works fine (we use the same oracle on AIX)
    is there any further setting for JDBC driver on AIX ? but it 's thin driver
    and the varchar type works fine at any paltform
    any help ?

    Hi jul!!!
    write like this:
    DATA : wa_flight_data TYPE bapisfldat,
    wa_add_info TYPE bapisfladd,
    wa_availability TYPE bapisflava,
    it_ret TYPE STANDARD TABLE OF bapiret2,
    wa_ret TYPE bapiret2.
    PARAMETERS : pa_carr TYPE sflight-carrid,
    pa_conn TYPE sflight-connid,
    pa_date TYPE sflight-fldate.
    CALL FUNCTION 'BAPI_FLIGHT_GETDETAIL'
    EXPORTING
    airlineid = pa_carr
    connectionid = pa_conn
    flightdate = pa_date
    IMPORTING
    flight_data = wa_flight_data
    additional_info = wa_add_info
    availibility = wa_availability
    TABLES
    *EXTENSION_IN =
    *EXTENSION_OUT =
    return = it_ret.
    write : / 'Flight Data: ',
    wa_flight_data-AIRLINEID,
    wa_flight_data-AIRLINE,
    wa_flight_data-CONNECTID,
    wa_flight_data-FLIGHTDATE,
    wa_flight_data-AIRPORTFR,
    wa_flight_data-CITYFROM,
    wa_flight_data-AIRPORTTO,
    wa_flight_data-CITYTO,
    wa_flight_data-DEPTIME,
    wa_flight_data-ARRTIME,
    wa_flight_data-ARRDATE,
    wa_flight_data-PRICE,
    wa_flight_data-CURR,
    wa_flight_data-CURR_ISO.
    similaryly for wa_add_info and wa_availability.
    becoz u r using work area directly in WRITE statement and
    wa_flight_data TYPE bapisfldat,
    wa_add_info TYPE bapisfladd,
    wa_availability TYPE bapisflava,
    contains both int and char data so u can print all of them together..They can be printed field by field.
    if any doubts..let me knw.
    hope it helps.
    kindly rewrd.

  • How can i make a soft return with pages shift enter does not work!

    how can i make a soft return with pages shift plus enter does not work!!

    On full keyboards with a numeric keypad, the key above the right shift is "return" & the one on the numeric section is "enter." On a Mac (or Apple IIgs ) they do have separate functions. On the "mini" keyboards, both names are on the same key, but "enter" is written in smaller letters. I'll have to check to see how that works on another Mac later today.

  • How to read file header/open filein binary mode

    i am using FileConnenction API to read from a file. how can i open a file in binary mode so that i can read file header. In other words i want to open a file in binary mode.

    You can always try looking at the [Header Signatures|http://www.techpathways.com/uploads/headersig.txt]. But it would probably be easier to adjust your application so it doesn't have to guess.
    ~

  • How can I include a carriage return in a expression

    How can I include a carriage return in a expression between text strings eg
    Expression 1 = Text1 & text2 & text3 & text4
    I need to display it as below
    Text1
    Text2
    Text3
    Text4
    adjusting the box the size doesn’t work as the text strings are variable lengths

    Message Edited by Ryan.S on 01-04-2007 08:17 PM
    Ryan Shi
    National Instruments
    Attachments:
    untitled.JPG ‏37 KB

  • How to retrieve multiple columns using "returning" in the Insert query.

    hi,
    wanted to know how to retrieve multiple columns using "returning" in the Insert Query.
    For retrieving one column we write the query as follows:
    Insert into TABLE values(1,2,3,4) returning COLUMN1 into PARAMETER
    But can we retrive multiple columns in the same query?
    am using oracle 10g and coding in .NET

    Hi,
    You can definetely get multiple values from a single query using the 'returning' clause.
    Eg : insert into emp (empno, ename, job, deptno) values (7324,'ADAM','MARKETING',30) returning ename, deptno into var1, var2; PN : var1 & var2 to be declared as varchar2 & number respectively.
    More insight into the 'RETURNING' clause in this link.
    http://www.samoratech.com/PLSQL/swArtPLSQLReturn.htm
    Regards,
    Bhanu.

Maybe you are looking for