Results 1 to 2 of 2

Thread: Handling MySQL LOB from JdbcTemplate

  1. #1

    Default Handling MySQL LOB from JdbcTemplate

    I'm using the JdbcTmplate to query for rows like this:

    Code:
    jt = new JdbcTemplate(dataSource);
    List rows = jt.queryForList("select * from Recipes");
    This gives me back an ArrayList that contains a HashMap per row (just as it should). I can easily loop through the List and extract row data for each column. So far so good.

    I have a column (called "NoteText')in the the queried table (called "Recipes") that's a MySQL LONGBLOB. The table definition is here:

    Code:
    CREATE TABLE Recipes
         (
         RecipeID             INT NOT NULL AUTO_INCREMENT,
         RecipeName           CHAR(255) NOT NULL,
         SequID               CHAR(50),
         ChefName             CHAR(50),
         Yield                CHAR(50),
         NoteTitle            CHAR(50),
         NoteText             LONGBLOB,
         ImageFilename        CHAR(50),
         MenuSectionID        INT NOT NULL,
         KEY (MenuSectionID),
         PRIMARY KEY (RecipeID),
         KEY (MenuSectionID),
         KEY (RecipeID),
         KEY (RecipeName),
         KEY (SequID)
         )\g
    When I grab that column's value from the HashMap for a particular row using row.get("NoteText") what am I getting? If i cast the HashMap value for that column to a String I get something like:

    Code:
    [B@241de8
    Obviously not what I want. I'd guess that what I'm getting back is an object and the above is the objects toString result.

    What's the best way to deal with LOB data coming back from a query through a JdbcTemplate?

    Thanks!

    - Gary

  2. #2

    Default

    Well, crap. I answered my own question again. I waded through the Spring source code and found that the HashMap for each returned record contains the exact same objects that are returned by JDBC's ResultSet.getObject() method.

    So, in my case, for a MySQL column of type LONGVARBINARY (which is actually intepreted at table-creation time as a LONGBLOB) I get back a byte array.

    - Gary

Similar Threads

  1. Replies: 3
    Last Post: Mar 1st, 2010, 05:45 PM
  2. CMT, JdbcTemplate and connection pools
    By jayschm in forum EJB
    Replies: 3
    Last Post: Apr 25th, 2005, 08:11 AM
  3. Replies: 8
    Last Post: Jan 9th, 2005, 10:24 AM
  4. Injecting JdbcTemplate instead of just DataSource?
    By ArtVandelay in forum Container
    Replies: 4
    Last Post: Oct 20th, 2004, 10:22 PM
  5. Replies: 1
    Last Post: Oct 16th, 2004, 07:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •