Why getBytes for VARCHAR type return byte array in UTF8 Codemap?

I have found that the getBytes method is double speed than getString method for CHAR and VARCHAR data type in the ResultSet object,when I am process Chinese I met this problem.

I have found that the getBytes method is double speed than getString method for CHAR and VARCHAR data type in the ResultSet object,when I am process Chinese I met this problem.

Similar Messages

  • How to use the JE database with other data types than byte arrays?

    Hi! I searched the javadoc of Berkley DB JE, for a way to introduce entry (but I need also retrieve) data with other type than byte arrays, e.g. String, or anything else, as int may be, etc.
    Still, I didn't find any such way, because the main (only?!) method to entry data into an open database - according what I found in javadoc - is:
    "public OperationStatus put(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException"
    and both this and the corresponding method for retrieves, are based on the same DatabaseEntry type, which allow only entry data on byte[] support.
    What if I need to use Strings or int, or even char? I must do a special conversion from these types, to byte[], to use the database?
    Thank you!

    On the doc page (this is also in the download package),
    http://download.oracle.com/docs/cd/E17277_02/html/index.html
    see:
    Getting Started Guide
    Java Collections Tutorial
    Direct Persistence Layer (DPL)
    All of these describe how to use data types other than byte arrays.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Display an object of Image type or Byte Array

    Hi, lets say i got an image stored in the Image format or byte[]. How can i make it display the image on the screen by taking the values in byte array or Image field?

    Thanks rahul,
    The thing is, i am generating a chart in a servlet
    and setting the image in the form of a byte [] to the
    view bean ( which is binded to the jsp, springs
    framework ). The servlet would return the view bean
    to the jsp and in the jsp, i am suppose to print this
    byte array so as to give me the image..
    I hope this makes sense.. pls help me ou!Well letme see if i got tht right or not,
    you are trying to call Your MODEL (Business layer / Spring Container) from a servlet and you are expressing that logic in form of chart (Image) and trying to save it as a byte array in a view bean and you want to print /display that as an image in a jsp (After Servlet fwd / redirect action) which includes other data using a ViewBean.
    If this is the case...
    As the forwaded JSP can include both image and Textual (hypertext too)..we can try a work around hear...Lets dedicate a Servlet which retreives byte [] from a view bean and gives us an image output. hear is an example and this could be a way.
    Prior to that i'm trying to make few assumptions here....
    1).The chart image which we are trying to express would of format JPEG.
    2).we are trying to take help of<img> tag to display the image from the image generating servlet.
    here is my approach....
    ViewBean.java:
    ============
    public class ViewBean implements serializable{
    byte piechart[];
    byte barchart[];
    byte chart3D[];
    public ViewBean(){
    public byte[] getPieChart(){
    return(this.piechart);
    public byte[] getBarChart(){
    return(this.barchart);
    public byte[] get3DChart(){
    return(this.chart3D);
    public void setPieChart(byte piechart[]){
    this.piechart = piechart;
    public void setBarChart(byte barchart[]){
    this.barchart = barchart;
    public void set3DChart(byte chart3D[]){
    this.chart3D = chart3D;
    }ControllerServlet.java:
    =================
    (This could also be an ActionClass(Ref Struts) a Backing Bean(Ref JSF) or anything which stays at the Controller Layer)
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException{
    /* There are few different implementations of getting   BeanFactory Resource
    In,the below example i have used XmlBeanFactory Object to create an instance of (Spring) BeanFactory */
    BeanFactory factory =
    new XmlBeanFactory(new FileInputStream("SpringResource.xml"));
    //write a Util Logic in your Implementation class using JFreeChart (or some open source chart library) and express the images by returning a  byte[]
    ChartService chartService =
    (GreetingService) factory.getBean("chartService");
    ViewBean vb = new ViewBean();
    vb.setPieChart(chartService.generatePieChart(request.getParameter("<someparam>"));
    vb.setBarChart(chartService.generateBarChart(request.getParameter("<someparam1>"));
    vb.set3DChart(chartService.generate3DChart(request.getParameter("<someparam2>"));
    chartService = null;
    HttpSession session = request.getSession(false);
    session.setAttribute("ViewBean",vb);
    response.sendRedirect("jsp/DisplayReports.jsp");
    }DisplayReports.jsp :
    ================
    <%@ page language="java" %>
    <html>
    <head>
    <title>reports</title>
    </head>
    <body>
    <h1 align="center">Pie Chart </h1>
    <center><img src="ImageServlet?req=1" /></center>
    <h1 align="center">Bar Chart </h1>
    <center><img src="ImageServlet?req=2" /></center>
    <h1 align="center">3D Chart</h1>
    <center><img src="ImageServlet?req=3" /></center>
    </body>
    </html>ImageServlet.java
    ==============
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
           byte buffer[];
            HttpSession session = request.getSession(false);
            ViewBean vb = (ViewBean) session.getAttribute("ViewBean");
            String req = request.getParameter("req");
            if(req.equals("1") == true)       
                buffer = vb.getPieChart();
            else if(req.equals("2") == true)
                 buffer = vb.getBarChart();
            else if(req.equals("3") == true)
                 buffer = vb.get3DChart();
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new ByteArrayInputStream(buffer));
            BufferedImage image =decoder.decodeAsBufferedImage() ;
            response.setContentType("image/jpeg");
            // Send back image
            ServletOutputStream sos = response.getOutputStream();
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
            encoder.encode(image);
        }Note: Through ImageServlet is a Servlet i would categorise it under presentation layer rather to be a part of Controller and added to it all this could be easily relaced by a reporting(BI) server like JasperServer,Pentaho,Actuate................
    Hope the stated implementation had given some idea to you....
    However,If you want to further look into similar implementations take a look at
    http://www.swiftchart.com/exampleapp.htm#e5
    which i believe to be a wonderful tutor for such implementations...
    However, there are many simple (Open) solutions to the stated problem.. if you are Using MyFaces along with spring... i would recommend usage of JSF Chart Tag which is very simple to use all it requires need is to write a chart Object generating methos inside our backing bean.
    For further reference have a look at the below links
    http://www.jroller.com/page/cagataycivici?entry=acegi_jsf_components_hit_the
    http://jsf-comp.sourceforge.net/components/chartcreator/index.html
    NOTE:I've tried it personally using MyFaces it was working gr8 but i had a hardtime on deploying my appln on a Portal Server(Liferay).If you find a workaround i'd be glad to know about it.
    & there are many BI Open Source Server Appls that can take care of this work too.(Maintainace wud be a tough ask when we go for this)
    For, the design perspective had i've been ur PM i wud have choose BI Server if it was corporate web appln on which we work on.
    Hope this might be of some help :)
    REGARDS,
    RaHuL

  • Returning byte array in JNI

    Hi,
    I am trying to return an array of byte from JNI to java. I read the tutorial but i still find it hard to understand.
    BYTE *encoded is the variable that has the contents to be sent back to java.
    jbytearray jb=encoded;
    ret jb;
    This does not seem to reurn anything!! Please help

    This is the JNI implementation of the method:
    public native byte[] returnArray (int size, byte initialValue).
    JNIEXPORT jbyteArray JNICALL Java_Test_returnArray
      (JNIEnv *env, jobject This, jint size, jbyte initialValue) {
           //-- No error handling is being done...
           jbyte* buf = new jbyte[size];
           memset (buf, initialValue, size);
           jbyteArray ret = env->NewByteArray(size);
           env->SetByteArrayRegion (ret, 0, size, buf);
           delete[] buf;
           return ret;
    }A jbyte is a signed char (a signed byte). You can mix signed bytes and unsigned bytes in C++ depending on your needs. This JNI method is the functional equivalent of the 100% Java function:
    public byte[] returnArray (int size, byte initialValue) {
        byte[] ret = new byte[size];
        for (int i = 0; i < size; ++i) {
            ret[i] = initialValue;
        return ret;

  • Return byte array

    Hello i have a function that return a byte array. I did it this way but i m wondering if it is the good way, so if someone can help improve it. Thank you.
    try
                InputStream is = new BufferedInputStream(new FileInputStream(nomFichierDemande));
                byte[] readData = null;
                while (is.available() > 0)
                    readData = new byte[is.available()];
                    is.read(readData);
    return readData;
            catch (IOException e)
                System.out.println("probleme lors de lecture de l'image");
                e.printStackTrace();
            }the source for my stream is an image file, bmp, gif or png, will it work the same for all kinds of file ?
    Thanks for help.
    Message was edited by:
    JusteUneQuestion
    Message was edited by:
    JusteUneQuestion

    (a) You should use File.length() rather than
    InputStream.available(): that's not what it's for.Hello i change the code like this :
    InputStream is = new BufferedInputStream(new FileInputStream(imageFile));
                    byte[] readData = null;
                    readData = new byte[(int)imageFile.length()];
                    is.read(readData);
                    return readData;Is it like this that u mean i have to use File.length, or was it only for the while loop ? I dont think that i need this while loop finally.
    (b) You should reconsider the whole idea of loading
    the entire file into memory. It doesn't scale. Sooner
    or later you'll encounter a file that doesn't fit
    into memory - then what?Can you give me a better idea? i thought about this but dont really know how to do to improve it. There is a limitation in the size of image anyway but i d like to have a good code in case for later.
    With this code i could read gif file but i m having problem for bmp so maybe its because it doesnt scale like you said.
    Message was edited by:
    JusteUneQuestion

  • Why does niDMM Fetch Multipoint Return Random Array of Results?

    Alright so I am using the following example https://decibel.ni.com/content/docs/DOC-25292. The goal is to get a constant resistance reading from 10 channels.  I have all the resistance readings coming in correctly.  But, I noticed that everytime I analyze the array of the resistance data, there is no consistency where the channels data is stored.  For example, channel 0 is tied to a 100 ohm resistor and all other 9 channels are tied to  220 ohm resistors. I will see the 100 ohm reading in the 0th element of the array but when the fetch gets called again the 100 ohm is now in the 5 element of the array. It seems random and uncontrollable, thoughts?

    Inside of the While loop is a niDMM Read Status VI.  That VI reads how many samples are in the backlog (number of samples already acquired).
    Here's what I am suggesting you do
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Acquire Data.PNG ‏11 KB

  • Validate item for varchar type

    hi
    i have a column drug_dosage which is a varchar and i want to put a check that it should not be less than or equal to 0
    data is entered as 10 ml / 100mg etc
    how can i do it ?
    is it possible ?
    thanks

    I would avoid storing the amount and unit together in one field. If the client demands the convenience of entering both values into a single field, I would create a calculated non-database field for this purpose. Updating the field would fire a trigger that parses its value and updates two hidden database fields -- one for the amount, and another for units. This would allow the amount field to be properly defined as a numeric field, and normal validation methods could be used. Define the visible field's calculation as a formula that concatenates the two hidden fields.
    Eric Adamson
    Lansing, Michigan

  • Create array of arbitrary dimensions / get Class object for primitive types

    Here's an interesting problem: is there any way to code for the creation of an n-dimensional array where n is only known at runtime (input by user, etc.)?
    java.lang.reflect.Array has a newInstance method which returns an array of an arbitrary number of dimensions specified by the int[] argument, which would give me what I want. However, the other argument is a Class object representing the component type of the array. If you want to use this method to get an array of a primitive type, is it possible to get a Class object representing a primitive type?

    That doesn't help, since the whole problem is that the number of dimensions aren't known until runtime. You can't simply declare a variable of type int[][] or use an int[][] cast, since the number of []'s is variable.
    The int.class construction was partly what I was looking for. This returns the array needed (assuming some read method):
    int dimensions = read();
    int size = read();
    int[] index = new int[dimensions];
    for (int i = 0; i < dimensions; i++)
        index[i] = size;
    Object myArray = Array.newInstance(int.class, index);The only problem is, as an Object, I can't use myArray usefully as an array. And I can't use a cast, since that requires a fixed number of dimensions.

  • Converting String to byte array

    Hi,
    There is a code for converting String to byte array, as follows:
         public byte[] toByteArray(String s)
              char[] c = s.toCharArray();
              int len = c.length;
              byte[] b = new byte[len * 2];
    for ( int i = 0 ; i < len ; i++ )
         b[i * 2] = (byte)(c);
         b[(i * 2) + 1] = (byte)(c[i] >> 8);
    return b;
    But this isn't doing the conversion properly. For example, for the � (euro) symbol, it converts to some other unreadable symbol. Also, same is the case for square brackets. Any idea why this' so? What's wrong with the above code?
    The encoding format is UTF-8.
    Thanks.

    > In fact, I tried with String.getBytes() too, but leads to the same problem, with those specific symbols.
    Did you try the String.getBytes(String charsetName) method?
    Both methods have been around since Java 1.1.
    It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of online documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
    Java� API Specifications
    Java� 1.5 JDK Javadocs
    Best of luck!
    ~

  • Reading a JPEG as a byte array.

    Hello everyone.
    I am developing a project which involves using JPEG images with Java. I would like to use the java.awt.Image class but there's a snag:
    I am reading the file in as a byte array and then need to pass the bytes to an object to be displayed as an image. "why not just read it as a normal JPEG file in the first place?!" I hear you say. Yes, this would be easier but there is a good reason as to why I am reading as a byte array first and this cannot be worked around.
    If anyone has some suggestions I'd very much like to hear them.
    All the best,
    P.M.

    If all you're going to do is display the image, then you can use Toolkit#createImage(byte[] imagedata). That's about as direct as you can get. If you plan on manipulating the images in any way, though, then as above post says ByteArrayInputStream + ImageIO is the way to go.
    "why not just read it as a normal JPEG file in the first place?!" I hear you say. Yes, this would be easier but there is a good reason as to why I am reading as a byte array first and this cannot be worked around.Fun fact: For the ImageIO package, reading from the file is actually faster than reading from an InputStream that references the file's contents as a byte[] array. Specifically, the ImageInputStream implementation that wraps the file is faster then the one that wraps a generic InputStream.

  • Generated Webservice proxy: Maximimum size of byte array

    Hi,
    We have generated a webservice proxy with JDeveloper (version 10.1.3.4.0) from a WSDL supplied by a .Net webservice. One of the Webservice returns a byte array. We are facing a problem when the size of the returned byte array exceeds the limit of 5 MB. We have tried to increase the heap size of the OC4J but that did not solve the problem.
    Does anyone know if there is a maximum value limit which can be passed through a byte array? Is it configurable?
    A workaround would be flushing the byte array in chunks, but the webservice returns the byte array as a single returned value.
    Regards,
    Sjoerd

    Hi,
    The webservice was called by Oracle Forms. The problem was solved by Metalink Note 562561.1 - Webservice Fails To Run With java.lang.OutOfMemoryError.
    Regards,
    Sjoerd

  • How to convert an int number to a byte array, and how to convert back?

    Hello, everybody,
    Just as the topic, if I have an int number(which should have 32-bit, or 4-byte), how can I convert it into a byte array. And also, how to convert it back.
    Thank you in advance!

    Alternatively you can use ByteBuffers to do this work for you
    // to a Byte Array
    int originalInt =...;
    ByteBuffer myBuffer = ByteBuffer.allocate(4);
    myBuffer.putInt( originalInt );
    byte myArray[] = myBuffer.array();
    // and back to an int
    ByteBuffer myOtherBuffer = ByteBuffer.wrap(myArray);
    int finalInt = myOtherBuffer.getInt();

  • Why is byte array not received in full?

    Hello,
    I have a pair of client/server programs. The client program sends in user and organization names, and the servlet (after some verification against the database) returns back an expiry date, and an encoded signature in a byte array.
    It works perfectly when a query string is given via a web browser; it also works perfectly with the servlet on a local Tomcat server. However, when the servlet is on a real remote machine, the byte array being sent back is truncated -- only the expiry date part is received. The signature is missing.
    I'm not sure why...
    The snippet of code in the servlet looks like this:
    //HttpServletResponse out from doGet()
    out.getOutputStream().write(returnArray);
    out.getOutputStream().flush();
    out.getOutputStream().close();
    the client part looks like:
    // url connects to the servlet
    URLConnection connect = url.openConnection();
    //Get the data it sends back
    InputStream inStream = connect.getInputStream();
    //Get the contents of the input stream, and convert to a string
    byte[] b = new byte[512];
    int numRead = inStream.read(b);
    By the way, when testing on local Tomcat, it works only if the outputStream is not flush()'ed or close()'ed. i.e. with those two statements, the byte array gets truncated regardless of where the servlet is located.
    It seems to be bugging me forever ... =(
    Thanks for your help!
    Tina

    I dont know if this makes sense but this mite be the problem
    Your client opens a URConnection con1 ... sends data to the servlet. Servlet does some processing sends data to the client. Now are u creating another URLConnection object to receive the data on the client?
    Though my analysis seems wrong coz ur getting one part of the data. Buf if you are using two different connection objects for sending and receiving, I think you are doing wrong.

  • Trying to send multiple types in a byte array -- questions?

    Hi,
    I have a question which I would really appreciate any help on.
    I am trying to send a byte array, that contains multiple types using a UDP app. and then receive it on the other end.
    So far I have been able to do this using the following code. Please note that I create a new String, Float or Double object to be able to correctly send and receive. Here is the code:
    //this is on the client side...
    String mymessage ="Here is your stuff from your client" ;
    int nbr = 22; Double nbr2 = new Double(1232.11223);
    Float nbr3 = new Float(8098098.809808);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(mymessage);
    oos.writeInt(nbr);
    oos.writeObject(nbr2);
    oos.writeObject(nbr3);
    oos.close();
    byte[] buffer = baos.toByteArray();
    socket.send(packet);
    //this is on the server side...
    byte [] buffer = new byte [5000];
    String mymessage = null; int nbr = 0; Double nbr2 = null;
    Float nbr3 = null;
    mymessage = (String)ois.readObject();
    nbr = ois.readInt();
    nbr2 = (Double) ois.readObject();
    nbr3 = (Float) ois.readObject();
    My main question here is that I have to create a new Float and Double object to be able to send and receive this byte array correctly. However, I would like to be able to have to only create 1object, stuff it with the String, int, Float and Double, send it and then correctly receive it on the other end.
    So I tried creating another class, and then creating an obj of this class and stuffing it with the 4 types:
    public class O_struct{
    //the indiv. objects to be sent...
    public String mymessage; public int nbr; public Double nbr2;
    public Float nbr3;
    //construct...
    public O_struct(String mymessage_c, int nbr_c, double nbr2_c, float nbr3_c){
    my_message = my_message_c;
    nbr = nbr_c;
    nbr2 = new Double(nbr2_c);
    nbr3 = new Float(nbr3_c);
    Then in main, using this new class:
    in main():
    O_struct some_obj_client = new O_struct("Here is your stuff from your client", 22, 1232.1234, 890980980.798);
    oos.writeObject(some_obj_client);
    oos.close();
    send code....according to UDP
    However on the receiving side, I am not sure how to be able to correctly retrieve the 4 types. Before I was explicitely creating those objects for sending, then I was casting them again on the receiving side to retrieve then and it does work.
    But if I create a O_struct object and cast it as I did before with the indiv objects on the receiving end, I can't get the correct retrievals.
    My code, on the server side:
    O_struct some_obj_server = new O_struct(null, null, null. null);
    some_obj_server = (O_struct)ois.readObject();
    My main goal is to be able to send 4 types in a byte array, but the way I have written this code, I have to create a Float and Double obj to be able to send and receive correctly. I would rather not have to directly create these objects, but instead be able to stuff all 4 types into a byte array and then send it and correctly be able to retrieve all the info on the receiver's side.
    I might be making this more complicated than needed, but this was the only way I could figure out how to do this and any help will be greatly appreciated.
    If there an easier way to do I certainly will appreciate that advise as well.
    Thanks.

    public class O_struct implements Serializable {
    // writing
    ObjectOutputStream oos = ...;
    O_struct struct = ...;
    oos.writeObject(struct);
    // reading
    ObjectInputStream ois = ...;
    O_struct struct = (O_struct)ois.readObject();
    I will be sending 1000s of these byte arrays, and I'm sure having to create a new Double or Float on both ends will hinder this.
    I am worried that having to create new objs every time it is sending a byte array will affect my application.
    That's the wrong way to approach this. You're talking about adding complexity to your code and fuglifying it because you think it might improve performance. But you don't know if it will, or by how much, or even if it needs to be improved.
    Personally, I'd guess that the I/O will have a much bigger affect on performance than object creation (which, contrary to popular belief, is generally quite fast now: http://www-128.ibm.com/developerworks/java/library/j-jtp01274.html)
    If you think object creation is going to be a problem, then before you go and cock up your real code to work around it, create some tests that measure how fast it is one way vs. the other. Then only use the cock-up if the normal, easier to write and maintain way is too slow AND the cock-up is significantly faster.

  • Returning an array type from a local method in Web Dynpro Java application

    Hi,
    In my project, we have a requirement to display 18 rolling months along with the year, starting from current month.
    How I am going to approach is that I will get the system date and get the current month and send the month and year value to a local method which will return 18 rolling months along with the year.
    But, when I tried to create a new method there is no option to return an array type. It was greyed out.
    So, we can not return an array type from a method from Web Dynpro for Java application?
    If so, what is the alternative and how am I going to achieve it?
    I will appreciate your help!
    Regards
    Ram

    HI
    You can create new methods in
      //@@begin others
      private ArrayList MyMethod(){
           // ** Put your code here
           return new ArrayList();
      //@@end
    Other option are create a context node with cardinality 0...n with one or more attributes, and in your method create the needed registers into this node. To read this values, you only need to read your context node.
    Best regards
    Edited by: Xavier Aranda on Dec 2, 2010 9:41 AM

Maybe you are looking for

  • Account statement for customer statement

    Hi, This is regarding to generate acc statement(customer statement), account type D(customer) thru F.27. At the summary of the statement by period bucket, when partial settlement done in different period from the invoice due date, I need the balance

  • Anyone's Mouse freezing since 10.4.8?

    Quite a few 10.4 upgrades ago my Griffin PowerMate (USB) began freezing up and was non-responsive for any app I had it programmed for. The only solution was to uplug the USB cable, wait a few seconds and then plug it back in. To this day that problem

  • IOS updation problem....

    Hi, i am a iphone 4 user , recently i wanted to the upgrade it to iOS5 . so i downloaded the iOS.... every thing was fine till it finished but in the processing phase the updation failed showing an error msg....i tried twice with same result...so can

  • Not Enough Memory Problem!

    Hi Guys, Often I am getting the following message when I open any AI file. (you can see the screen shot). Once I click 'OK' and re-open the same file, then It is coming properly without any problem. For your extra information: Using Software: Adobe C

  • Upgrade from iMac to Mac Pro - RAID5 options?

    I am currently using a 27" iMac 2.66 Ghz Core i5 for my main processing needs (RAW image file editing in Adobe Lightroom & Photoshop plus HDSLR footage editing in Final Cut) and am feeling constrained by my storage options (I don't like external encl