Storing and retrieving a serialized object in a database table

As an example, I created the following table:

mysql> create table objects (objectid int(10) not null auto_increment, 
name varchar(30), data blob, length int(6), primary key(objectid));
Query OK, 0 rows affected (0.12 sec)
 
mysql> desc images;
+----------+-------------+------+-----+---------+----------------+
| Field    | Type        | Null | Key | Default | Extra          |
+----------+-------------+------+-----+---------+----------------+
| objectid | int(10)     |      | PRI | NULL    | auto_increment |
| name     | varchar(30) | YES  |     | NULL    |                |
| length   | int(6)      | YES  |     | NULL    |                |
| data     | blob        | YES  |     | NULL    |                |
+----------+-------------+------+-----+---------+----------------+

In the following code, a string array is serialized and stored in the objects table.

Main.java:

import java.sql.*;
import java.io.*;  
 
public class Main {
   public static void main(String []args) {
      try {
         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
         Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.0.1/esus", 
                                                       "joris",
                                                       "mypass");
 
         String stringArray[] = { "this", "is", "a", "test" };       
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream oos = new ObjectOutputStream(baos);
         oos.writeObject(stringArray);
 
         PreparedStatement insertStmt = conn.prepareStatement(
                                       "INSERT INTO objects (name, length, data) " +
                                       "VALUES (?, ?, ?)");
         insertStmt.setString(1, "stringarray");
         byte[] buffer = baos.toByteArray();
         insertStmt.setInt(2, buffer.length);
         insertStmt.setBytes(3, buffer);
         insertStmt.execute();
 
         oos.close();
      }
      catch(Exception e) {
         e.printStackTrace();
      }
   } 
}

To read it back in:
Main.java:

import java.sql.*;
import java.io.*;  
 
public class Main {
   public static void main(String []args) {
      try {
         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
         Connection conn = DriverManager.getConnection("jdbc:mysql://192.168.0.1/esus", 
                                                       "joris",
                                                       "mypass");
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SELECT name, length, data FROM objects");
      
         if (rs.next()) {
            String name = rs.getString("name");
            int length = rs.getInt("length");
            byte[] buf = rs.getBytes("data");
 
            ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buf));
            String[] stringArray = (String[]) ois.readObject();
            ois.close();
 
            for (int i=0; i<stringArray.length; i++) {
               System.out.println(stringArray[i]);
            }
         }
      }
      catch(Exception e) {
         e.printStackTrace();
      }
   } 
}

outputs:

this
is
a
test