Storing a Blob into MySql  from a JTextArea

I'm using Java 1.4.1, MySql 4.0.12, and MyConnector/J 3.06
I have an application with a JTextArea and I want to put the contents of the JTextArea into the database stored as a Blob Object. The only reason I'm using Blob is because varchar is limited in lenght by 255 characters.
The problem I am having is actually creating the Blob Object. I get a null pointer exception no matter what I do.(Even when there is text in the JTextArea) Please take a look at my code and please help me out if you can.
I'm not sure if I'm using the java Blob correctly as it cannot be instantiated and it's an interface not a class.
Please give me any suggestions including if there is a better way to doing this without using a Blob object. Thanks in advance.
// create a new Blob Object, must initialize to something
Blob tempBlob = null;
// viewOrdData.notes is the JTextArea
if (viewOrdData.notes.getText().length() > 0) {
// THIS IS THE LINE WHERE I GET THE NULL POINTER EXCEPTION
// I tried initial position both 0 and 1
tempBlob.setBytes(0,viewOrdData.notes.getText().getBytes())
stmt.executeUpdate(
"UPDATE WORKORDER "+
"SET NOTES = "+tempBlob+" "+ // NOTES is of type Blob
"WHERE WRKID = "+viewOrdData.workOrderID); // primary key

Now, Storing a Blob into Database from a JTextArea or any text components becomes easy with the SerialBlob class( javax.sql.rowset.serial.SerialBlob - JDK 1.5).
For eg..
For Storing a Blob to Database
pstmt.setBlob(1,new  SerialBlob(jtextArea.getText().getBytes()));For Retrieving a Blob to JTextArea
SerialBlob sblob = new SerialBlob(rs.getBlob("FieldName"));
jTextArea.setText(new String(sblob.getBytes(1, (int)sblob.length())));Hope this serves this problem well.
Regards,
R.Amirdha Gopal.

Similar Messages

  • How to display and save a picture stored as BLOB in MySQL database in Jsp?

    Hello i am doing a dataentry form where in i will display the picture stored as Blob in MySQL database to the browser. The form also allow changing the picture and updating the picture Blob in the database.
    How can i do it? I try this
    <img src'"<%=rs.getBlob("picture")%> but it doesn't display the picture.
    another thing, how can i save it in the database, if is use the file field in the html form?
    thanks in advance for your help.

    Hello i am doing a dataentry form where in i will display the picture stored as Blob in MySQL database to the browser. The form also allow changing the picture and updating the picture Blob in the database.
    How can i do it? I try this
    <img src'"<%=rs.getBlob("picture")%> but it doesn't display the picture.
    another thing, how can i save it in the database, if is use the file field in the html form?
    thanks in advance for your help.

  • Loading images stored as BLOBs in MySQL

    Hello,
    For various reasons, I would prefer to store binary data like images and videos as BLOBs within a MySQL database and have Flash retrieve that content directly from the database as opposed to getting it from a URL on a fileserver. So, I have written a PHP script that Flash calls which does a database query and returns the bitmap data from the BLOB. I have verified that the image data is being sent from the database through the PHP, but Flash either doesn't display the image or gives me an error saying that it is an unknown type.
    Here is the AS3:
    var imageLdr:Loader = new Loader();
    //imageLdr.dataFormat = "binary";
    imageLdr.load(new URLRequest("http://www.XXXXXXXXXX.com/cgi/getToken.php"));
    imageLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage, false, 0, true);
    function loadImage(evt:Event):void {
        trace("Now in loadImage...");
        tokenHolder.addChild(imageLdr);
        addChild(tokenHolder);
        trace("loadImage complete...");
    Here is the getToken.php file code:
    <?php
    $hostname = "dbhost";
    $username = "username";
    $password = "pword";
    mysql_connect($hostname, $username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database'),history.go(-1)</script></html>");
    mysql_select_db($username);
    $query = "SELECT content FROM media WHERE id=2";
    $result = mysql_query($query);
    $data = mysql_result($result, 0);
    $im = imagecreatefromstring($data);
    if ($im !== false) {
        header('Content-Type: image/png');
        imagepng($im);
        imagedestroy($im);
    else {
        echo 'An error occurred.';
    ?>
    Is there a way to get Loader() to accept bitmap image data that is retrieved from a BLOB in a database? Should I try to get PHP to mimic the response from an HTTP server or is there another way to load bitmap data stored as a BLOB into a display object?
    Thanks!

    Hey
    Thanks for sharing your problem and how you get data as image in php. It gave me clue about my problem about getting blob info from database to as3 and displat it as image. So what i did is:
    In this fuction;
    function  loadImage(evt:Event):void {
        trace("Now in loadImage...");
         tokenHolder.addChild(imageLdr);
        addChild(tokenHolder);
         trace("loadImage complete...");
    I changed it to:
    public function loadImage(evt:Event):void {
                    trace("Now in loadImage...");
                    img= evt.currentTarget.content as Bitmap;
                    trace("loadImage complete...");
    img is a Bitmap variable and I used Image component and stated its source as imgg ( source={img} )
    I hope you can solve your problem
    Have a good day...

  • Send files stored as blob in mysql as attachment

    Hey guys,thanks for your attention.
    Here is my question:
    Now,in my website I can upload some files into MYSQL DB,and I want to select some of these files as attachment to be sent to customer.
    I know it is very easy if the file is stored as a file in a particular directory,what i need is to get the path of the file and then use a javamail function "attachFile(path)",how can i do it when the file is stored as blob?Is there any javamail function which can be used to manipulate this process?

    Use ByteArrayDataSource, included with JavaMail 1.4 or available in
    the demo directory in earlier versions.

  • Informix Stored Procedure Blobs into CF

    New CF user here. I'm trying to use Informix Stored
    Procedures to return blobs to CF. When using cfquery, all worked
    fine, but it seems I can only return the non-blob fields when using
    stored procedures. According to the documentation, I can define a
    pointer (references text) in the stored procedure, but I don't know
    how to get the blob to display in CF since I cannot use it in the
    RETURNING section of the procedure, Any thoughts to also get the
    blob in additional to the 5 other character values that are
    returned just fine? Thanks in advance.

    Better to use a PL/SQL stored
    procedure than a
    function, as "older" versions of ColdFusion could not handle
    the retun value from an Oracle function. Not sure about 6.1, but
    you can use them with MX7, but you have to capture your return code
    in a variable named cfstoredproc.StatusCode, such as below:
    <cfstoredproc procedure="one_fucntion.getosuser"
    returncode="yes" datasource="gcadmin" debug="yes">
    <cfprocparam cfsqltype="cf_sql_integer" type="IN"
    value="2" >
    </cfstoredproc>
    <cfoutput>#cfstoredproc.statusCode#</cfoutput>
    I would rewrite your PL/SQL SP as a procedure with an OUT
    parameter that you could capture in a CFPROCPARAM.
    Also, you would only use CFPROCRESULT if you were returning
    the results of a query that you had selected into a referrence
    cursor in your proc (OPEN out_ref_cursor FOR SELECT...... etc.),
    but you would have to contain your procedure in a package and have
    a ref cursor type declared globally , etc. Your use of CFPROCRESULT
    is not necessary to return a single value from a procedure, only a
    CFPROCPARAM of type="out".
    Bottom line, as written, what you have isn't really even
    close... sorry.
    Phil

  • Diaplay  Word file stored in blob into a browser using JSP

    Dear All
    I have files stored in oracle table in a blob field.I store the files using forms 10g and webutil. I can upload the files and display them successfully in forms, however when i use JSP to retrieve the files and display them in Internet Explorer, I'm able to display the pdf files, bmp , jpg and video but I'm getting junk characters when I try displaying (word , excel , access or powerpoint files which might contain arabic Characters )
    the code I use to display the files is as follows :
    <%
    try
    Connection conn = null;
    String username=session.getAttribute("username").toString().toUpperCase();
    String password=session.getAttribute("password").toString().toUpperCase();
    String ip = "*****************";
    String sid = "***************";
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@"+ip+":1521:"+sid,username,password);
    String par = request.getParameter("LETTER");
    String par1 = request.getParameter("SERIAL");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select * from TableName where PK1 like '"+par+"'"+" and PK2 like '"+par1+"'" );
    if (rs.next())
    Blob pic = null;
    byte[] blobBytesArray = null;
    OutputStream stream = response.getOutputStream();
    pic = rs.getBlob("BLOBFIELD");
    int len = new Integer( new Long( pic.length()).toString() ).intValue();
    blobBytesArray = pic.getBytes(1,len);
    if (blobBytesArray != null)
    if (blobBytesArray.length > 0 )
    stream.write(blobBytesArray) ;
    catch(Exception e)
    System.out.println("Exception: " + e.getMessage() + "<BR>");
    %>
    can you please guide me of how to display other file types.
    Best Regards.

    Hello,
    Ideally when you store the document put the content-type in a column and set the content type in your JSP. This will indicate to the browser what is the type of file and you should not have any issue with any type.
    Regards
    Tugdual Grall

  • Unable to insert into mysql from flash burrito

    I'm having issues inserting a record to mysql, if I use the test "test operation and use these values the it works fine, but now in the android app.
    values in my test operation
        id:0,
        type:"cool",
        navn:"vegar 16"
    the getall method works fine, and shows up on the network monitor, but the button dont work at all, nothing happends in the network monito, if I debug it I can see that the button works, any suggestions on what Im doing wrong?
    code in my view:
    <?xml version="1.0" encoding="utf-8"?>
    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:kunderservice="services.kunderservice.*"
            title="Home">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
                import valueObjects.Kunder;
                protected function list_creationCompleteHandler(event:FlexEvent):void
                    getAllKunderResult.token = kunderService.getAllKunder();
                protected function button_clickHandler(event:MouseEvent):void
                    var item:Kunder = new Kunder();
                    item.id=0
                    item.navn="vegar"
                    item.type ="test"
                    createKunderResult2.token = kunderService.createKunder(item);
            ]]>
        </fx:Script>
        <fx:Declarations>
            <s:CallResponder id="getAllKunderResult"/>
            <kunderservice:KunderService id="kunderService"/>
            <s:CallResponder id="createKunderResult2"/>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <s:List id="list" x="35" y="45" width="409" height="193"
                creationComplete="list_creationCompleteHandler(event)" labelField="navn">
            <s:AsyncListView list="{getAllKunderResult.lastResult}"/>
        </s:List>
        <s:Button id="button" x="20" y="406" label="Button" click="button_clickHandler(event)"/>
        </s:View>

    I really appreciate your help. Yes indeed, debugging and seeing what is going on in general is most difficult with flash!
    Once I get this cracked I should be able to complete a lot of what I am trying to achieve.
    After inserting some echo's into my php as such:
    <?php
    $player = $_POST['player'];
    $tournament = $_POST['tournament'];
    $position = $_POST['position'];
    $prize = $_POST['prize'];
    mysql_connect("localhost", "root","poker");
    echo "onnected to database"
    mysql_select_db("poker");
    echo "database connected";
    mysql_query("INSERT INTO results(player,tournament,position,prize) VALUES
    ('$player','$tournamnet','$position','$prize')");
    echo "result added";
    ?>
    The returned info is a load of nonsense to me:
    response from server:  %3C%3Fphp%0A%24player%20=%20%24%5FPOST%5B%27player%27%5D%3B%0A%24tournament%20%3D%20%24%5 FPOST%5B%27tournament%27%5D%3B%0A%24position%20%3D%20%24%5FPOST%5B%27position%27%5D%3B%0A% 24prize%20%3D%20%24%5FPOST%5B%27prize%27%5D%3B%0A%0Amysql%5Fconnect%28%22localhost%22%2C%2 0%22root%22%2C%22poker%22%29%3B%0Aecho%20%22onnected%20to%20database%22%0Amysql%5Fselect%5 Fdb%28%22poker%22%29%3B%0Aecho%20%22database%20connected%22%3B%0Amysql%5Fquery%28%22INSERT %20INTO%20results%28player%2Ctournament%2Cposition%2Cprize%29%20VALUES%20%0A%28%27%24playe r%27%2C%27%24tournamnet%27%2C%27%24position%27%2C%27%24prize%27%29%22%29%3B%0Aecho%20%22re sult%20added%22%3B%0A%3F%3E

  • Storing  WAVE file into database from sql plus.

    dear all
    I have create a table with two attributes,sl_no number and song long raw type.
    what will be the insert command to insert a .wav file into the database.if not then you can give me some alternate solution also.
    thanks.

    You can use DBMS_LOB.LoadFromFile, I assume you would load these as a BLOB.
    The documentation can be found on technet at
    urlhttp://technet.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a89852/dbms_20b.htm#1009007
    [\url]
    An alternative would be to use java to read the file from the file system, and serve it up as a CLOB or BLOB, and INSERT it into the database from there.
    Good Luck,
    Eric Kamradt

  • Play video stored as BLOB in MySQL

    I would like to use JMF applet to play videos which is stored in mySQL as BLOB. I have finished a solution by playing a video file and store filename as a column in DB. It is easy for programming but hard for future DB management. I want t o improve my design by storing video in DB column. I know it is not hard to do in Oracle. But I have to insist on using mySQL.
    Could anyone has any clue of it? Thanks in advance.

    Use ByteArrayDataSource, included with JavaMail 1.4 or available in
    the demo directory in earlier versions.

  • How to insert a parameter into MySql from JSP using bean

    Hai.........
    The files i hav used are: DbConnection.java, LogBean.java, login.jsp, checkUser.jsp, existingUser.jsp, newUser.jsp...................
    I hav problem in newUser.jsp................................................
    ie: plz giv an appropriate code for this code:.........................................
    resultSet = connectionBean.execUpdate("insert into userLogin values('"+uName+"','"+pWord+"') ");
    Message was edited by:
    jaseemkhan

    Here is the code fragment.
    File file = new File ("c:\\t.gif");
    FileInputStream in = new FileInputStream (file);
    int len = (int)file.length();
    PreparedStatement pst = null;
    pst = conn.prepareStatement ("insert into blob_table values (1, ?)");
    pst.setBinaryStream (1, in, len);
    pst.executeUpdate();
    pst.close();
    conn.commit();

  • Storing a voice into file using RTP

    Hello every body
    Can I store the voice Conversation which transmitted between two end points?
    Im using AVtransmit and AVReceive for transmitting and Receiving. I want to store the voice in to a file. is it possibe? kindly provide me the code if
    Thanking you in advancly
    Sreenath Kulkarni

    Now, Storing a Blob into Database from a JTextArea or any text components becomes easy with the SerialBlob class( javax.sql.rowset.serial.SerialBlob - JDK 1.5).
    For eg..
    For Storing a Blob to Database
    pstmt.setBlob(1,new  SerialBlob(jtextArea.getText().getBytes()));For Retrieving a Blob to JTextArea
    SerialBlob sblob = new SerialBlob(rs.getBlob("FieldName"));
    jTextArea.setText(new String(sblob.getBytes(1, (int)sblob.length())));Hope this serves this problem well.
    Regards,
    R.Amirdha Gopal.

  • SQLite3 and BlobsI am having trouble learning how insert blobs into SQLite

    I am having trouble learning how insert blobs into SQLite for the iphone. Is there a way to insert a blob into sqlite3 from the command line? I know it was possible with sql using
    INSERT INTO temponly(name , pic) values( 'velan',
    load_file('e:/mysql/images/Click.gif')) ;
    but I don't think load_file is supported on sqlite.
    Also, I need to insert the blobs from my iphone app. I saw a C program called eatblob.c which goes through the following just to INSERT a blob into sqlite
    1. read the jpeg image file into memory , doing appropriate malloc based on size
    2. prepare an sqlite statement with ? values
    3. bind the malloc'd memory to the ?
    4. execute an sqlite step
    etc. etc. etc....
    This is quite a bit of work just to do an INSERT ???
    The reason I'm doing this is my iphone app has a lot of tiny (20x20) images that get downloaded to the phone periodically from the server. Plus, there are a number of images that come loaded with the application. I was going to save all of these in SQLite. So, I need the command line tool to load up the initial images that come with the app, then I need code to download the images from the server and load them into the database. Of course, reading them out is necessary!
    Please help if you can!? Its late..and I'm blurry eyed from googling SQLIte3 blobs...

    Thank you for your quick reply Liam! You know, I checked the web forms list when I got that error message and the form isn't there. I was having trouble the other day when another of my forms kept getting deleted.
    Sorry if this is a stupid question (I'm a BC newbie) but I want to be sure so I can get this project finished... The proper workflow would be to create this form myself in Web Forms then insert it into the Registration - Buy template using the modules toolbox?
    Thanks to you I may get this done on time still... if my PayPal set up works

  • How to read the data from an excel file into MYSQL by java language

    Hi all,
    I have some data in excel spread sheet and I want to put the data into MYSQL data base. I created the tables in MYSQL> How can I write a program in JAVA that puts the value from excel sheet to mysql??
    I would appreciate your help
    regards

    By typing code at the keyboard... but presumably you meant to ask what code you should type.
    To get data out of Excel there are a few alternatives. The Google keywords I would use to find them are "java excel". I use Apache POI but there are other possibilities, I believe. As for getting the data into MySQL once you have extracted it from Excel, you would use JDBC. But you already knew that, didn't you? You did find the JDBC forum.
    In general it's better to ask a specific question on a forum. If you don't have a clue (which is the way we all start out) then just telling people that isn't going to be helpful. The best you're going to get is links to tutorials, which you could perfectly well have found for yourself by simple web searches.

  • I need help proving the date tag on a photo stored in my iPhoto is from the date it was sent to my iphone/date it was imported into iphoto - and that it is NOT the date the photo was actually taken.  Please help!

    I need help proving the date tag on a photo stored in my iPhoto is from the date it was sent to my iphone/date it was imported into iphoto - and that it is NOT the date the photo was actually taken.   I recieved a photo via text on my iphone and then I synced my iphone to my macbook and now it is in iphoto.  I already know that the date on the photo per the tag that shows up on it in iphoto is NOT the date the photo was actually taken.  I need article or literature or something confirming the tag is from when it was sent to the iphone and/or when it was imported.  I greatly appreciate some assistance!

    All I am trying to do is find something on a forum board or article etc stating that the the date showing in iphoto could be the date it was imported or synced or sent to me and not the actual date taken.
    The date on the photo could be anything because you can edit the date with iPhoto or any of 100 apps, free and paid for. So, the date on the photo will prove nothing, I'm afraid.
    Regards
    TD

  • How to bulk import data into CQ5 from MySQL and file system

    Is there an easy way to bulk import data into CQ5 from MySQL and file system?  Some of the files are ~50MB each (instrument files).  There are a total of ~1,500 records spread over about 5 tables.
    Thanks

    What problem are you having writing it to a file?
    You can't use FORALL to write the data out to a file, you can only loop through the entries in the collection 1 by 1 and write them out to the file like that.
    FORALL can only be used for SQL statements.

Maybe you are looking for