Converting from string to blob

hi,
how can I convert String to blob in java programming

convert to char array then to int array and then look here:
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Blob.html

Similar Messages

  • Convert from String data type to Character data type

    Hi...,
    I'm a beginner. I try to make a program. But I don't know how to convert from string to data type. I try to make a calculator with GUI window. And when somebody put "+" to one of the window, I just want to convert it to Character instead of String.
    Sorry of my bad english..
    Please help me....
    Thanks

    String s = "a+b";
    char theplus = s.charAt(1);

  • Convert from String to HashMap

    Hi
    Can any body pls tell us how to convert from String to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into HashMap?

    Hi
    Can any body pls tell us how to convert from String
    to HashMap
    I have one string str="Col1=200, Col2=225";
    So how can i convert that string varibale into
    HashMap?
    Map map = new HashMap();
    String[] parts = str.split(", ");
    for (int i = 0; i < parts.length; ++i) {
        String[] entry = parts.split("=");
    map.put(entry[0], entry[1]);

  • Convert from String to Int

    Hi,
    I have a question.
    How do I convert from String to Integer?
    Here is my code:
    try{
    String s="000111010101001101101010";
    int q=Integer.parseInt(s);
    answerStr = String.valueOf(q);
    catch (NumberFormatException e)
    answerStr="Error";
    but, everytime when i run the code, i always get the ERROR.
    is the value that i got, cannot be converted to int?
    i've done the same thing in c, and its working fine.
    thanks..

    6kyAngel wrote:
    actually it convert the string value into decimal value.In fact what it does is convert the (binary) string into an integer value. It's the String representation of integer quantities that have a base (two, ten, hex etc): the quantities themselves don't have a base.
    To take an integer quantity (in the form of an int) and convert it to a binary String, use the handy toString() method in the Integer class - like your other conversion, use the one that takes a radix argument.

  • Convert from String to boolean ??

    hi everyone..
    is there any way to convert from String (as a class) to boolean (as a primitive type) ?
    thunx

    I used : Boolean.valueOf(s).booleanValue(); ,I got the same error.What same error? Surely not this one:
    cannot resolve simple in parseBoolean method??
    equals is OK, but I think it is not convert method,
    the prev. solutions by equals don't convert the value of s (String).Yes it does, for any reasonable definition of "converts". In fact, that is essentially how parseBoolean() is implemented. From the JDK 5.0 source code, class java.lang.Boolean:
         return ((name != null) && name.equalsIgnoreCase("true"));

  • Convert from String to Long

    Hello Frineds I want to convert from String to Long.
    My String is like str="600 700 250 300" and I want to convert it to long and
    get the total value in to the long variable.like the total of str in long varible should be 1850.
    Thank You
    Nilesh Vasani

    Maybe this would work?
    StringTokenizer st = new StringTokenizer(yourString, " ");
    long l = 0;
    while(st.hasMoreTokens()) {
        l += Long.parseLong(st.nextToken()).longValue();
    }

  • Convert from String to float

    How do I convert from String to float?

    Hi,
    you can use a Double for example - assuming value is that string to parse
    float f;
    try { Double d = new Double(value); f = d.floatValue(); }
    catch (NumberFormatException e) { f = 0.0; } // error - string value could not be parsed
    // here use your float fHope, that helps
    greetings Marsian
    P.S.: the Double class is usefull for that, because you also can get intValue(), doubleValue() or longValue() out of it for example. The StreamTokenizer for example parses numbers also only to double.

  • How to convert  from  varchar to blob ?

    How to convert from varchar to blob ?
    thanks

    Here is a small PL/SQL block that we have used to convert varchar2 to blob.
    declare
    cursor get_blob is
    select blob_statement
    from report
    where report_id = 205
    FOR UPDATE OF blob_statement;
    v_loc blob;
    v_raw_buffer raw(32767);
    v_amount binary_integer := 32767;
    v_offset binary_integer := 1;
    v_buffer VARCHAR2(32767);
    begin
    open get_blob;
    fetch get_blob into v_loc;
    close get_blob;
    v_buffer := 'Sample text';
    v_raw_buffer := utl_raw.cast_to_raw(v_buffer);
    v_amount := utl_raw.length(v_raw_buffer);
    dbms_lob.write(v_loc, v_amount, v_offset, v_raw_buffer);
    commit;
    end;

  • Date Formatting, Converting from String to Timestamp

    I am trying to convert a string date to timestamp.
    I have tried a couple of different ways to arrive at the end result.
    I am basically trying to convert a date in the "dd-MM-yyyy" format to a timestamp.
    If I use the following code, I get a date like this "18-May-2004 12:00:00 AM".
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy);
    Date dContractDate = sdf.parse("18-05-2004");
    long dateInMilli = dContractDate.getTime();
    bHelp.bcontractdate = new Timestamp(dateInMilli);
    How can I make this code display the current time not midnight or some defaulted value?
    Thanks.

    I think a clever person would reuse their Date.classObject and call Date.setTime() as opposed to always
    rolling out a new Date()
    Not really a question of cleverness. Your code wins
    nothing. Objects are not magically created and garbage collected in the ether.
    The cost of creating a Date is nothing
    compared to the cost of a format() call. True, but not valid a valid statement pertaining to the issue which is
    "does always rolling dates suffer a performance hit?"
    Plus you lost clarity Maybe you loose track of your code if you don't make new Objects all the time,
    but I have never suffered from this.
    Why do you think Sun provided the setDate() method?
    and thread-safety.I have only had Thread issues when I didn't program them properly.
    Luckilly I always program the correctly ;) (Touch wood)
    The facts as I seem are thus:
    Rolling new dates on a 1.83 GHZ PC incurrs on average
    a 19% penalty. Here is the proof.
    Save this program and save it as DateTest.java
    If you don't want to waste the time here are the results of running it
    through the default 10 iterations.
    Running 10 iterations.
    Reuse of dates is 27% more efficient
    Reuse of dates is 17% more efficient
    Reuse of dates is 18% more efficient
    Reuse of dates is 20% more efficient
    Reuse of dates is 20% more efficient
    Reuse of dates is 17% more efficient
    Reuse of dates is 17% more efficient
    Reuse of dates is 20% more efficient
    Reuse of dates is 20% more efficient
    Reuse of dates is 18% more efficient
    Gaining "nothing " actually = 19% on average
    Low percent diff = 17 High percent diff = 27
    Run it 100 times and it should still be around 19%
    With the hi time being about 47% (Probably the result of garbage collecting)
    //////////////////////////////////// <PROOF> ///////////////////////////////////////
    import java.util.Date;
    public class DateTest
    DateTest()
    public int run()
    int percent = 0;
    int loopCount = 0;
    Date date = null;
    int z=0;
    long start1=0,end1=0,start2=0,end2=0,now=0;
    int time1 = 0,time2 = 0;
       now = System.currentTimeMillis();
       date = new Date(now);
       loopCount = 10000000;
       start1    = System.currentTimeMillis();
       for(z=0;z<loopCount;z++)
          now = System.currentTimeMillis();
          date.setTime(now);
       end1 = System.currentTimeMillis();
       start2    = System.currentTimeMillis();
       for(z=0;z<loopCount;z++)
          now   = System.currentTimeMillis();
          date  = new Date(now); // use 'now' so test loops are =.
       end2 = System.currentTimeMillis();
       time1 = (int)(end1 - start1);
       time2 = (int)(end2 - start2);
       percent = ((time2-time1)*100/time2);
       System.out.println("Reuse of dates is "+percent+"% more efficient");
       return percent;
    public static void main(String args[])
    int z=0;
    int lowP=100,hiP = 0;  // lowpercent/highpercent
    DateTest d = new DateTest();
    int loopCount = 0;
    long totals   = 0;
    int average   = 0;
    int values[];
    int retVal = 0;
       try // Yea olde Lazy person's command line handler :)
          loopCount = Integer.parseInt(args[0]);
       catch(Exception any)
          loopCount = 10;
       if(loopCount == 0)
          loopCount = 10;
       values = new int[loopCount];
       System.out.println("Running "+loopCount+" iterations.");
       for(z=0;z<loopCount;z++)  //
          retVal = d.run();
          if(lowP > retVal)
             lowP = retVal;
          if(hiP < retVal)
             hiP = retVal;
          values[z] = retVal;
       for(z=0;z<loopCount;z++)
          totals += (long)values[z];
       average = (int)(totals/loopCount);
       System.out.println(" Gaining \"nothing \" actually = "+average+"% on average");
       System.out.println("Low percent diff = "+lowP+" High percent diff = "+hiP);
    }////////////////////////////////// </PROOF> /////////////////////////////////////////
    Your "nothing" is in fact on average about a 19% performance hit. per call.
    These inefficiencies build up and java is infested with the,
    Was it not so the java would run much more efficiently than it now does.
    Ask yourself; why did Sun supply the setDate() method???
    (T)

  • Is it possible to convert from string to variant?

    Hi!
    I would like to convert a text string to variant. I'm doing this because I would like to merge a couple of signals and then save all the signals in a lvm-file. Could someone please explain how to convert from text to variant, is it possible?
    Thanks in advance!
    Regards,
    Mattias
    Attachments:
    Merge signals.JPG ‏27 KB

    What you are attempting to do is possible, but might not give you the results you expect.  All you need to do is convert your string to an array of U8s using the String to Byte Array conversion primitive.  In the file, you will get a single character per line of the file expressed as the ASCII code.  When you read it, convert to U8s, then use Byte Array to String to get your string back.
    You may also want to read up on LVM files.  There are several places to put strings that work a little better than this.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • Converting from String to float and vice versa

    I'm interested in people's thoughts on where common logic to convert between various field types should be stored in an application to minimise code duplication and maintenance.
    I have an application which consists of an object and a jPanel which displays and maintains this object. The object contains a number of private float fields which are accessed by getters and setters. The jPanel contains one jTextField for each of the fields within the object.
    Currently I have numerous lines of code in the jPanel to convert between the values needed by the getters and setters in the object (i.e. float) and the String value used by the jTextFields. This code handles cases where the String value may be blank or null.
    I've thought that one alternative to having all this conversion/validation code in the jPanel is to create a second set of getters and setters for each field which accept and return String values.
    What do people think about this? Is it advisable for only have one getter and setter for a variable? Should I put the conversion/validation logic for each field into a seperate common routine?
    Thanks,
    James.

    Hi James,
    You should go with whatever works best for you. By creating multiple getters and setter you save yourself from repeating the same code throughout your program.

  • Convert from String to Date for storing in SQL Server 2000

    Hi,
    I've accepted some values from a user using a form in HTML.Now using Servlets I transfer the value to my java code .
    I want to know how can I convert a DATE accepted from the user thats presently in "String" format to the "datetime" format for SQL Server2000.
    Please guide me with some steps and I shall be grateful.
    Thanks

    The java.text.SImpleDateFormat class is most probably of use.
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String enteredDate = "25/12/2006";
    java.util.Date utilDate = sdf.parse(enteredDate);
    java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());You can then use the java.sql.Date with the "setDate()" method of a prepared statement. This method would be database independant, as you are setting an actual date, not depending on a specific format on the database end.

  • Leading Zeroes are lost when convert from string to int

    What I'm trying to do is simple yet the solution has seemed difficult to find.
    I have a system that requires 4 digit numbers as "requisitionNo". The system uses JSPs and accepts the 4 digit number that the user inputs (fyi - duplicate handling is already managed). The input number (rNumber) is of STRING type and in the action (using struts) is converted to an int:
    int requisitionNo = Integer.parseInt(rNumber);At that very line the issue is that when the user inputs a number with leading zeros such as: "0001" the 3 leading zeros are chopped off in the INT conversion. The application validation kicks in and says: "A 4 digit number is required" which is by design. The work around has been that the user has been putting in number that start with 9's or something like that, but this isn't how the system was intended to be used.
    How do I keep the leading zeroes from being lost instead of saving a number "1" to the database how do I keep it saving "0001" to the database? Would I just change everything to STRING on down to the database? or is there another number type that I can be using that will not chop off the leading zeroes? Please provide short code references or examples to be more helpful.

    Yeah, I have to agree here that leading zeroes make no sense. I figured that out when I started to look into this problem. The only requirement that exists is that the user wants it to be a 4 digit number due to some other requirement they have themselves.
    So what I'm gathering from what I've read in the responses thus far is that I should change the validation a bit to look at the STRING for the 4 required digits (which are really 4 characters; maybe I should add CLIENT side numeric validation; currently its doing server side numeric/integer validation; or maybe change up the server side validation instead???) and if they are ALL GOOD then let the application save the int type as it wants to. IE: Let it save "0001" as just "1" and when I come back to DISPLAY this saved number to the user I should append the string of "000" in front of the 1 for display purposes only? Am I understanding everyone correctly?

  • Converting from a BASE64 BLOB

    I have a BLOB column which contains BASE64 encoded jpegs.
    I want to decode these from BASE64 such that I can get the original JPEG.
    I've written a function to do this (based on an example found here but modified slightly since my source is a BLOB not a CLOB: http://blogs.dayneo.co.za/2012/07/base64-decode-using-plsql.html)
         FUNCTION base64_decode(p_file IN BLOB)
         RETURN BLOB IS
          l_BASE64_LN_LENGTH constant pls_integer := 30000;
          l_result           blob := empty_blob();
          l_pos              number := 1;
          l_amount           number;
          l_buffer           raw(32767);
          l_rbuf             raw(32767);
          l_length           pls_integer;
         begin
          DBMS_LOB.createTemporary(l_result, true, dbms_lob.CALL);
          l_length  := DBMS_LOB.getLength(p_file);
          while l_pos <= l_length loop
           l_amount := l_BASE64_LN_LENGTH;
           dbms_lob.read(p_file, l_amount, l_pos, l_rbuf);
           l_buffer := utl_encode.base64_decode(l_rbuf);
           dbms_lob.writeappend(l_result,
                                utl_raw.length(l_buffer),
                                l_buffer);
           l_pos    := l_pos + l_BASE64_LN_LENGTH;
          end loop;
          return l_result;
         END base64_decode;This works absolutely fine where the input BLOB (p_file) is less than 30000 bytes i.e. I can save the generated BLOB and open it in a graphics application.
    However, if the input BLOB (p_file) is larger than 30000 bytes, when I save the resultant BLOB (i.e. l_result) and try to open it with a graphics application such as Windows Picture Viewer I get the message "Drawing failed".
    Any thoughts, comments or suggestions would be very much appreciated.
    Thanks,
    Andy

    >
    This works absolutely fine where the input BLOB (p_file) is less than 30000 bytes i.e. I can save the generated BLOB and open it in a graphics application.
    However, if the input BLOB (p_file) is larger than 30000 bytes, when I save the resultant BLOB (i.e. l_result) and try to open it with a graphics application such as Windows Picture Viewer I get the message "Drawing failed".
    >
    You can't just append and try to decode an arbitrary number of bytes in your loop. You are like having this problem
    >
    Conversion needs to be done in properly aligned chunks. And I use base64 conversions for MIME purposes.
    >
    See the solution by Oracle ACE Billy Verreynne Posted: May 29, 2012 9:28 AM at
    Re: BASE64 (PDF) CLOB to BLOB

  • Converting from string to double (formula)

    Hi All,
    I have a formula stored in properties file (i am doing some android dev) and retrieveing that formula using following stmt
    double c = 35.0;
    String res = this.getResources().getText(R.string.celsiusfahrenheit).toString();
    The returned value of string res is (1.8*c)+32
    How do i make the above stmt to substitue value of c into above equation and returned me the result value.
    thx
    vinod

    vinod_kmr wrote:
    Hi All,
    I have a formula stored in properties file (i am doing some android dev) and retrieveing that formula using following stmt
    double c = 35.0;
    String res = this.getResources().getText(R.string.celsiusfahrenheit).toString();
    The returned value of string res is (1.8*c)+32
    How do i make the above stmt to substitue value of c into above equation and returned me the result value.
    thx
    vinodas I understand you actually want to solve. if so, and res always returns that formula, then you can skip the properties file and just solve it already. something like:
    double result = (1.8*c) + 32.0if the result you are looking for is res with the value of the double substituted for c in the formula then the first step is to convert the the double c into a string and sticking that in res using String.replace(). something like
    res = res.replace("c", Double.toString(c));of course I don't know if String in android is like java.lang.String (same with Double) but I'm sure an equivalent exist.

Maybe you are looking for

  • Cut/Paste not working in Microsoft Remote Desktop for Mac

    Sirs, I am using Microsoft Remote Desktop V8.05 build 24428 on a Mac under the latest Mavericks OS, and I find that Cut and Paste are not working. When I paste on Remote Desktop Windows always pastes the last thing cut/copied under the Windows remote

  • Which version macbook pro is this? and how much ram?

    Hi Everybody! I just bought this 2.4ghz core 2 duo macbook pro 2nd hand:-) It's probably the mid 2007 version. It's annonced with a max RAM upgrade of 3 gb, but it's to cheap to buy 4gb (2x2)!! How does it work? Does OSX used the last gig of ram from

  • Reinstall lion due to missing recovery partition?

    Dear Apple Community, Here is my situation: I have a 3-partioned drive inside my iMac. One has Lion installed, one has SL, and another is an empty partion. Unfortunatly, there is no recovery partition installed on my computer. While I am fully aware

  • Can anyone explain to me how to print a page of Thumbnails of the same photo?

    Can anyone explain to me how to print a page of Thumbnails of the same picture, for wallet photos?

  • Errors about Translation (localization)

    Hello I have found 2 errors about translation (localization) for the hebrew version. my product is : Ideatab A3000 Android version: 4.2.2 build number: A3000_A422_000_130617_ww_sms who should I contact to report which bugs are found? will it be fixed