I've recently started to take a closer look at Juergen's LOB handler
classes and they look very solid. It would be a shame not exposing them
to the Jdbc Object package - primarily SqlUpdate. I have started to
test a few ideas. I added a constructor accepting a LobHandler to the
SqlParameter class. I also added a SqlLobValue class for holding the
input stream and the length. This is what the usage would look like:
LobHandler lobHandler = new DefaultLobHandler(); // or
OracleLobHandler
String sql = "insert into docs (doc_id, description , added,
document) values(?, ?, ?, ?)";
SqlUpdate su = new SqlUpdate(ds, sql);
su.declareParameter(new SqlParameter("id", Types.INTEGER));
su.declareParameter(new SqlParameter("desc", Types.VARCHAR));
su.declareParameter(new SqlParameter("added", Types.DATE));
su.declareParameter(new SqlParameter("lob", Types.BLOB,
lobHandler));
su.compile();
Object[] inval = new Object[4];
inval[0] = new Integer(newId);
inval[1] = "Doc One";
inval[2] = new java.sql.Date(new Date().getTime());
File in = new File("word.doc");
int len = (int) in.length();
FileInputStream is = new FileInputStream(in);
inval[3] = new SqlLobValue(is, len);
int count = su.update(inval);
is.close();
A few tweaks to the PreparedStatementCreateorImpl class and this
actually ran against both Oracle and PostgreSQL.
I think we could easily support all the different methods that
LobHandler supports:
byte[]
BinaryStream
String
AsciiStream
CharacterStream
Any thoughts or ideas?
Thomas
|