Announcement Announcement Module
No announcement yet.
Handling MySQL LOB from JdbcTemplate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Handling MySQL LOB from JdbcTemplate

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

    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:

    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)
    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:

    [[email protected]
    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?


    - Gary

  • #2
    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