What to use to store binary data in Java

Hello,
I have to read data stored as varbinary in the SQL database. What kind of class, data type I can use to store binary data from database?
I need to store binary data finally in ByteBuffer.
Please, help.
Thank you!

Unfortunately, when I am doing following I am getting an exception:
ByteBuffer lUTF8BIN=ByteBuffer.allocate(6)
byte [] lTempByteArray lTempByteArray = Recordset.getBytes(VarBinColumn);
if (lUTF8BIN.remaining()>=lTempByteArray.length)
lUTF8BIN.put(lTempByteArray);
Exception is java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported data conversion

Similar Messages

  • How to store binary data in Java

    I need to show news in my web aplication.So I am retrieving news from a Feed Server in which the field GEN_UNICODE_MESSAGE_1 gives the news data.News consists of both English/Arabic data.So how will I store the binary content in JAVA and how can I display the news in JSP?
    I tried storing the binary content in ByteArrayInputStream and appended it using StringBuilder.But I didnt get the desired output.Output is seen as ÇáÎáíÌíÉ ááÇÓÊËãÇÑÇáãÌãæÚÉÇáÔÑßÉÇáÇãÓÈÊãÈÑÓÈÊãÈÑÅÌãÇá.Please help me.
    Here GEN_UNICODE_MESSAGE_1 is of type BINARY.
    try{
    BufferedInputStream in=new BufferedInputStream(new ByteArrayInputStream((byte[])msg.getField("GEN_UNICODE_MESSAGE_1").value.get(h)));
    //ByteArrayInputStream in=new ByteArrayInputStream(((byte[])msg.getField("GEN_UNICODE_MESSAGE_1").value.get(h)));
    StringBuilder builder = new StringBuilder();
    byte[] buff=new byte[1024];
    int len;
    while ((len=in.read(buff))!=-1){
    builder.append(new String(buff,0,len));
    String incomingmsg=builder.toString();
    }catch(IOException e){}
    Edited by: Alance on May 7, 2010 10:12 PM

    BufferedInputStream bis=new BufferedInputStream(new ByteArrayInputStream((byte[])msg.getField("GEN_UNICODE_MESSAGE_1").value().toString().getBytes()));
    BufferedReader br = new BufferedReader(new InputStreamReader(bis));What on earth is all this?
    1. What is the type of msg.getField("GEN_UNICODE_MESSAGE_1").value()?
    2. Whatever that type is, you are then converting it to a String.
    3. You are then converting that to bytes.
    4. You are then casting that to byte[], which it already is,
    5. You are then wrapping a ByteArrayInputStream around that.
    6. ... and an InputStreamReader round that ...
    7. ... and a BufferedReader around that ...
    8. ... and reading lines
    9. ... and appending them to a StringBuilder
    10. ... and converting that to a String.
    Which you already at at step 2.
    String incoming = msg.getField("GEN_UNICODE_MESSAGE_1").value().toString();Not sure whether that's correct given the charset issues, but if not the problem starts at step 2. In any case steps 3-10 add precisely nothing.
    This is all pointless. The key question is (1). Answer that first.
    2. The type of String.getButy
    >
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = br.readLine()) != null) {
    sb.append(line + "\n");
    br.close();
    String incomingmsg=sb.toString();

  • Need Help Improving Memory Use of a Binary Data Insert

    I am using the following code to insert binary data from an InputStream into a database.
    It seems to be very memory inefficient. It works fine for small files. But for large files it really causes memory issues.
    Imagine this coming from a 22mb file upload. This method first copies 22megs of data to an ArrayList. It then copies the data to an array. It then creates another array to store the bytes. Finally it inserts the data to the database.
    Is there another way I can get data into a format that the setBytes() method can accept without using so much memory?
            * Inserts Binary Database into the Database
           private void insertData(InputStream stream){
             ConnectionPool pool = (ConnectionPool)properties.getProperty("zeusportal.connectionpool");
             Connection conn = null;
             BufferedReader in = new BufferedReader(new InputStreamReader(stream));
             try{
               byte[] byteArray;
               int streamlength = 0;
               int value;
                  //Read Data Into Arraylist
               ArrayList list = new ArrayList();
               while((value = stream.read()) != -1){
                 list.add(new Integer(value));
               Object data[] = list.toArray();
                  //Create Byte Array to store bytes
               byteArray = new byte[data.length];
                  //Copy Data from ArrayList into Byte Array
               for(int iCounter = 0; iCounter < byteArray.length; ++iCounter){
                 Integer curr = (Integer)data[iCounter];
                 byteArray[iCounter] = curr.byteValue();
                  //Retrieve Connection
               conn = pool.getConnection();
               conn.setAutoCommit(false);
               PreparedStatement pstmt = conn.prepareStatement("INSERT INTO table (video_name, video_description, video_contenttype, video_content, upload_date, objecttype, objectid) values(?, ?, ?, ?, ?, ?, ?)");
                  //Insert Data Attributes into PreparedStatement
               pstmt.setString(1, this.name);
               pstmt.setString(2, this.description);
               pstmt.setString(3, this.contenttype);
               pstmt.setBytes(4, byteArray);
               pstmt.setInt(6, objectType);
               pstmt.setLong(7, objectID);
               this.date = new java.util.Date();
               pstmt.setLong(5, date.getTime() / 1000L);
               pstmt.execute();
               pstmt.close();
               conn.commit();
               conn.setAutoCommit(true);
             catch(SQLException sqle){
               throw new RuntimeException(sqle);
             catch(IOException ioe){
               throw new RuntimeException(ioe);
             finally{
               if(conn != null){
                 pool.releaseConnection(conn);
             return;
           }//insertData

    I have tried storing the data in a temp file and then retrieved the length of the file. That however didn't work as the data was corrupted for anything but the smallest files.
            * Inserts the data into the database
           private void insertData(InputStream stream){
             ConnectionPool pool = (ConnectionPool)properties.getProperty("zeusportal.connectionpool");
             Connection conn = null;
             BufferedInputStream in = new BufferedInputStream(stream);
             try{
                      //Create Temporary File to Store Binary Data
                File file = File.createTempFile(Math.random()+"", ".tmp");
                      //Create a writer to write to the Temp File
                OutputStream writer = new FileOutputStream(file);
                      writer = new BufferedOutputStream(writer);
               int value;
                  //Copy Data to Temp File
               while((value = in.read()) != -1){
                 writer.write(value);
               writer.flush();
               writer.close();
                  //Read new InputStream from Temp File
               stream = new FileInputStream(file);
               //Retrieve Connection
               conn = pool.getConnection();
               conn.setAutoCommit(false);
                  //Inset Data to the database
               PreparedStatement pstmt = conn.prepareStatement("INSERT INTO zeusportalvideos (video_name, video_description, video_contenttype, video_content, upload_date, objecttype, objectid) values(?, ?, ?, ?, ?, ?, ?)");
               pstmt.setString(1, this.name);
               pstmt.setString(2, this.description);
               pstmt.setString(3, this.contenttype);
               pstmt.setBinaryStream(4, stream, (int) file.length());
               pstmt.setInt(6, objectType);
               pstmt.setLong(7, objectID);
               this.date = new java.util.Date();
               pstmt.setLong(5, date.getTime() / 1000L);
               pstmt.execute();
               pstmt.close();
               stream.close();
               file.delete();
               conn.commit();
               conn.setAutoCommit(true);
             catch(SQLException sqle){
               throw new RuntimeException(sqle);
            catch(IOException ioe){
               throw new RuntimeException(ioe);
             finally{
               if(conn != null){
                 pool.releaseConnection(conn);
             return;
           }//insertData

  • DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file

    Hi
    DAQ vi to perform digital write and read measurements using 32 bits binary data saved in a file
    Two main
    sections:
    1)     
    Perform
    write and read operations to and fro different spread sheet files, such that
    each file have a single row of 32bits different binary data (analogous to 1D
    array) where the left most bit is the MSB. I don’t want to manually enter the
    32 bits binary data, I want the data written or read just by opening a file
    name saves with the intended data.
          2)     
    And
    by using test patterns implemented using the digital pattern generator or  build digital data functions or otherwise, I need to
    ensure that the     
                binary data written to a spreadsheet file or any supported file type
    then through the NI-USB 6509 is same as the data read.
    I’m aware I can’t use the simulated
    device to read data written to any port but if the write part of the vi works I
    ‘m sure the read part will work on the physical device which I’ll buy later.
    My Plan
    of action
    I’ve
    created a basic write/read file task and a write/read DAQ task for NI USB 6509
    and both combine in a while loop to form a progress VI which I’m confuse of how
    to proceed with the implementation.
    My
    greatest problem is to link both together with the correct functions or operators
    such that there are no syntax/execution errors and thus achieve my intended
    result.
    This
    project is one of my many assignments for my master thesis, so please i’ll
    appreciate every help as I’m not really efficient with LabVIEW programming but
    I prefer it because is fun and interesting if I get to know it.
    Currently I’m
    practicing with LabVIEW 8.6/NI DAQmx 8.8 Demo versions and NI USB 6509
    simulated device.
    Please see
    the attached file for my novice progress, thanks in
    advance for the support
    Rgds
    Paul
    Attachments:
    DIO_write_read DAQ from file.vi ‏17 KB

    What does your file look like?  The DAQmx write is expecting a single U32 value, not an array of I64. 
    Message Edited by vt92 on 09-16-2009 02:42 PM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal

  • Conversion from scaled ton unscaled data using Graph Acquired Binary Data

    Hello !
    I want to acquire temperature with a pyrometer using a PCI 6220 (analog input (0-5V)). I'd like to use the VI
    Cont Acq&Graph Voltage-To File(Binary) to write the data into a file and the VI Graph Acquired Binary Data to read it and analyze it. But in this VI, I didn't understand well the functionnement of "Convert unscaled to scaled data", I know it takes informations in the header to scale the data but how ?
    My card will give me back a voltage, but how can I transform it into temperature ? Can I configure this somewhere, and then the "Convert unscaled to scaled data" will do it, or should I do this myself with a formula ?
    Thanks.

    Nanie, I've used these example extensively and I think I can help. Incidently, there is actually a bug in the examples, but I will start a new thread to discuss this (I haven't written the post yet, but it will be under "Bug in Graph Acquired Binary Data.vi:create header.vi Example" when I do get around to posting it). Anyway, to address your questions about the scaling. I've included an image of the block diagram of Convert Unscaled to Scaled.vi for reference.
    To start, the PCI-6220 has a 16bit resolution. That means that the range (±10V for example) is broken down into 2^16 (65536) steps, or steps of ~0.3mV (20V/65536) in this example. When the data is acquired, it is read as the number of steps (an integer) and that is how you are saving it. In general it takes less space to store integers than real numbers. In this case you are storing the results in I16's (2 bytes/value) instead of SGL's or DBL's (4 or 8 bytes/value respectively).
    To convert the integer to a scaled value (either volts, or some other engineering unit) you need to scale it. In the situation where you have a linear transfer function (scaled = offset + multiplier * unscaled) which is a 1st order polynomial it's pretty straight forward. The Convert Unscaled to Scaled.vi handles the more general case of scaling by an nth order polynomial (a0*x^0+a1*x^1+a2*x^2+...+an*x^n). A linear transfer function has two coefficients: a0 is the offset, and a1 is the multiplier, the rest of the a's are zero.
    When you use the Cont Acq&Graph Voltage-To File(Binary).vi to save your data, a header is created which contains the scaling coefficients stored in an array. When you read the file with Graph Acquired Binary Data.vi those scaling coefficients are read in and converted to a two dimensional array called Header Information that looks like this:
    ch0 sample rate, ch0 a0, ch0 a1, ch0 a2,..., ch0 an
    ch1 sample rate, ch1 a0, ch1 a1, ch1 a2,..., ch1 an
    ch2 sample rate, ch2 a0, ch2 a1, ch2 a2,..., ch2 an
    The array then gets transposed before continuing.
    This transposed array, and the unscaled data are passed into Convert Unscaled to Scaled.vi. I am probably just now getting to your question, but hopefully the background makes the rest of this simple. The Header Information array gets split up with the sample rates (the first row in the transposed array), the offsets (the second row), and all the rest of the gains entering the for loops separately. The sample rate sets the dt for the channel, the offset is used to intialize the scaled data array, and the gains are used to multiply the unscaled data. With a linear transfer function, there will only by one gain for each channel. The clever part of this design is that nothing has to be changed to handle non-linear polynomial transfer functions.
    I normally just convert everything to volts and then manually scale from there if I want to convert to engineering units. I suspect that if you use the express vi's (or configure the task using Create DAQmx Task in the Data Neighborhood of MAX) to configure a channel for temperature measurement, the required scaling coefficients will be incorporated into the Header Information array automatically when the data is saved and you won't have to do anything manually other than selecting the appropriate task when configuring your acquisition.
    Hope this answers your questions.
    ChrisMessage Edited by C. Minnella on 04-15-2005 02:42 PM
    Attachments:
    Convert Unscaled to Scaled.jpg ‏81 KB

  • How can I find out what is using all our home data?

    We have a huge amount of data every month but over the past few months we are cracking thru it like crazy.  I want to know what is using it all.  We have changed passwords to ensure it wasn't outside this house.

    Hello,Do you have mobile devices and tablet/s connected to your modem?If so, turn off "Background Data" in Data settings plus any automatic updates etc etc It could be that someone in your home is using it with high data downloads? If ou have multiple PCs, turn off automatic updates in Windows, to advise but not download.In your portable devices, there are a mutitiude of apps that update without your knowledge. Would need more information from you to make specific suggestions Hope this helps you RegardsProfessor PhoneI'm not a Telstra employee.  I have been a mobile subscriber since 1963.If my advice has been helpful, a Kudo  "tick"    would be most appreciated.If my advice has solved your problem, please also mark it as a Solution  

  • How do I find out what is using up all my data at 3 different times of the day?

    At exactly the same time, 3 times a day something on my computer is using up all my data allowance.  Any suggestions on how to determine what is doing that?  I have turned off Windows update to manual.

    With Windows, Msconfig in diagnostic startup. If the problem goes away, use selective startup to isolate system services or startup items as the problem group. Once you know which group you can use the tab to enable individual programs in the group then restart to test for the problem. Don’t forget to use Normal Startup in Msconfig to return the system to normal. If you find the problem program, either uninstall it or use the program’s configuration to fix it.

  • Programming binary data in Java

    A use case contains a series of yes/no options. In the web front end, they are in the form of checkboxes. For anyone with CS background, it is easy to think of a series of binary data which is an integer in Java. One advantage of this approach is that no change is needed for the application back-end DB table if those option entities are changed such as adding more options.
    The data conversion is a problem with the approach, however, in Java. It is not too bad to convert a series of binary data to an integer:
              StringBuilder sb = new StringBuilder();
              sb.append(option1 ? "1" : "0");
              sb.append(option2 ? "1" : "0");
              Integer.valueOf(sb.toString());     I have some problems with a conversion from an integer to a series binary data:
           Integer.toBinaryString(anInteger)which doesn't preserve the number of digits if the significant digit is zero.
    Any better way?

    vwuvancouver wrote:
    A use case contains a series of yes/no options. In the web front end, they are in the form of checkboxes. For anyone with CS background, it is easy to think of a series of binary data which is an integer in Java. One advantage of this approach is that no change is needed for the application back-end DB table if those option entities are changed such as adding more options.
    For anyone with practical experience in databases and servers it is easy to think of that as likely being the wrong solution. ESPECIALLY if you anticipate more options might be needed.
    Any better way?Depends on what you are actually doing.
    But if and only if you want to manipulate bits then the easiest way is to use the bit operators that java has. And it would not require any conversions at all. I would like to think someone with a formal (education) background in computer science should have some idea of how to do that.

  • What's using up my mobile data?

    When ever I check my data it seems to go down everytime I check it, even when I'm not using any Internet etc. Just wondering if there are any apps secretly running which are using it up, or is it something else?

    You can also check in Data Usage under the graph which applications are using data and how much they are using.
    What are your thoughts about this forum? Let us know by doing this short survey.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • What's Using All of My Data Storage?!?! Mysterious "Other Data" ???

    Has anyone found out the actual solution to this problem?!?! I had 12 of 13 gb used, less than 1 gb free. Why?? I've NEVER downloaded ANY games or side loaded ANY Android apps. After the 10.2 update I deleted all of my nonessential apps, including FB, Twitter, Foursquare, and LinkedIn. That leaves me with password protector, adobe reader, The Weather Channel, and Box (which, by the way, doesn't load anymore so it is pretty much useless). Now I have 8.81 used and 4.37 free. It's been said that the OS takes 2.5 gb. So what is the rest of this stuff and why can't anyone get rid of it without doing a wipe? Seriously, we have to do a wipe? All of my pictures, videos and music are on my SD card and it has 19.7 of 29.7 used. My pics, vids, and music is less than 12 gb. So why is my card full of that stuff, too?? And why am I yelling?!?! I've deleted everything that I can, even important things, cleared my cache and cookies, never downloaded games or Android apps, and never downloaded leaked updates. Why isn't Blackberry giving a solution? Or at least telling what this stuff is. Does anyone have any insight? Thanks in advance.

    Playzoutside wrote:
    Has anyone found out the actual solution to this problem?!?! I had 12 of 13 gb used, less than 1 gb free. Why?? I've NEVER downloaded ANY games or side loaded ANY Android apps. After the 10.2 update I deleted all of my nonessential apps, including FB, Twitter, Foursquare, and LinkedIn. That leaves me with password protector, adobe reader, The Weather Channel, and Box (which, by the way, doesn't load anymore so it is pretty much useless). Now I have 8.81 used and 4.37 free. It's been said that the OS takes 2.5 gb. So what is the rest of this stuff and why can't anyone get rid of it without doing a wipe? Seriously, we have to do a wipe? All of my pictures, videos and music are on my SD card and it has 19.7 of 29.7 used. My pics, vids, and music is less than 12 gb. So why is my card full of that stuff, too?? And why am I yelling?!?! I've deleted everything that I can, even important things, cleared my cache and cookies, never downloaded games or Android apps, and never downloaded leaked updates. Why isn't Blackberry giving a solution? Or at least telling what this stuff is. Does anyone have any insight? Thanks in advance.
    The sizes of the apps you deleted are not very large - FB 98MB. Twitter 8.4MB, Foursquare 13MB, Linkedin 5.7MB
    Look in Storage and Access - Device Storage details - Storage - Pie Chart and list of apps.
    Mine is System 2.55GB, Apps 1.68GB, User Files 63 MB, Free 8.89Gb.
    I have 5 pages of apps, which includes 8 android apps.
    Pictures and videos are all on sd card.

  • Store XML data in java cache (hashmap as a key value pair)

    Hi,
    I have to store a xml file in java cache so that I can resue it .The flow is like this :
    DAO layer reads database ,create an xml and sends to --> IBM MQ-->our java code should read this xml file over MQ and store it in a cache (preferably hashmap).The file contain unique id for every customer.
    How can we achieve this.One way is to store the xml as an string as key is "id" and value is whole xml.Is this a good way or any other way is available.Please suggest.
    Sample xml:
    <Client>
    <ClientId>1234</ClientId>
    <ClientName>STechnology</ClientName>
    <ID>10</ID>
    <ClientStatus>ACTIVE</ClientStatus>
    - <LEAccount>
    <ClientLE>678989</ClientLE>
    <LEId>56743</LEId>
    - <Account>
    <AccountNumber>9876543678</AccountNumber>
    </Account>
    </LEAccount>
    - <Service>
    <Cindicator>Y2Y</Cindicator>
    <PrefCode>980</PrefCode>
    <BSCode>876</BSCode>
    <MandatoryContent>MSP</MandatoryContent>
    </Service>
    </Client>
    Thanks
    Sumit

    A HashMap can work, but then still store the customer related data in a bean (and perhaps it will have some child objects as well, if for example the service subelement can repeat). So you get a HashMap of Customer objects, with the clientID as the index into the hashmap.

  • How to use Binary data in Oracle(OLE DB)?

    I have the Oracle 8.1.6, I can store VARCHAR2 or CBLOB into oracle database(by DBTYPES_STR). But can NOT store binary data(DBTYPES_BYTES)such as RAW, BLOB into database. My platform is VC++,ATL,OLE DB, consumer. I try to use the Oracle tools to do that, but do not successful? Can you tell me how to store data into binary column in oracle?
    Thank you

    Better to trim those values after the form submission.
    Once you put them into form,
    user may also makes mistake by hitting space, right?
    Also, by trimming all form fields after submission, you will
    be sure that your DB is clean... no whitespaces on it.
    Well unless someone insert data directly onto it :)

  • Binary data in xml document

    Hi,
    I have some tables and I store binary data in varchar2 column. I want to create xml document from one of the table using xsql. What will happen to binary data? Can xml document takes care of binary data? I will appreciate, if I get the answer/solution for this.
    Thanks
    Prasanta De

    Hi,
    I have some tables and I store binary data in varchar2 column. I want to create xml document from one of the table using xsql. What will happen to binary data? Can xml document takes care of binary data? I will appreciate, if I get the answer/solution for this.
    Thanks
    Prasanta De

  • How to convert XML data into binary data (opaque data)

    Hi,
    I am trying to develop a process that delivers files after reading data from a database.
    However, it is required not to deliver the data immediately. We want to perform some checks before the files get written.
    So the way we want to design this is,
    1. Read data from database (or any other input). The data is in XML format (this is a requirement, as in general, we have xml data)
    2. This data is written, opaquely, to a JMS queue that can store binary data, along with what is the filename of the file that would be written (filename is passed using JMS Headers)
    3. When required, another process reads the JMS queue's binary data, and dumps into a file
    The reason I want to use opaque data while inserting in the JMS queue is, that enables me to develop a single process in Step 3 that can write any file, irrespective of the format.
    My questions are
    1. How to convert the xml data to opaque data. In BPEL I may use a embedded java, but how about ESB. Any other way....?
    2. how to pass filename to the jms queue, when payload is opaque. Can I use a header attribute...custom attributes?
    3. Which jms message type is better for this kind of requirement - SYS.AQ$_JMS_BYTES_MESSAGE or SYS.AQ$_JMS_STREAM_MESSAGE

    Ana,
    We are doing the same thing--using one variable with the schema as the source of the .xsl and assigning the resulting html to another variable--the content body of the email, in our case. I just posted how we did it here: Re: Using XSLT to generate the email HTML body
    Let me know if this helps.

  • Ideal column type for Binary Data ??

    Hi there,
    I must store binary data of fixed length (e.g. IP address of 4/16 bytes) into a table and manipulate that table over C++ / OCI.
    The database server is running on either SUN/SPARC or LINUX/i86. The clients are running on a broad range of systems (NT/i86, LINUX/x86, SUN/SPARC, ..).
    I am worried about the OCI layer modifying char/varchar values while transmission ...
    Whats the best approach ??
    Use CHAR/VARCHAR or use the variable length RAW even for fixed length binary data ??
    Any help would be greatly appreciated,
    Tobias
    null

    I guess RAW is the best approach

Maybe you are looking for

  • External display via Mini DisplayPort to DVI no longer works with MacBook.

    I had not used my external monitor in the last several weeks. I believe there have been a few OSX Lion updates since the last time I used the external monitor. I had installed all the updates prior to connecting my external monitor again. However, a

  • Preview mode function in Illustrator CS3

    Hey peepz, Just wondering if there is a preview mode like the one in InDesign, where you can block everything (shortcut = W) around the artboard with a gray color to see your work as if it were cropped. It's a really great feature in InDesign and I w

  • Mac OS X 10.5.5 finder and top bar doesn't work

    Hi Guys, I'm having a problem with following applications after upgrading to 10.5.5 : Finder, iPhoto, iMovie, Mail.app etc.. Suddenly all of them stopped working... I did a home work. Searched forums, mailing lists etc.. I can't find Finder in my App

  • Is BO Edge XI 3.1 compatible with this OS

    Is BO Edge XI 3.1 compatible with Windows 7 ? Are there any issues?

  • Run external executable from script

    Hi, it's possible launch an external executable (Es. .\smsclient.exe "3201234567" "SMSClient.exe Tested on %date% at %time%")  from script .aef (not from CAD)?