db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lars Clausen ...@statsbiblioteket.dk>
Subject Re: need jdbc insert CLOB example
Date Fri, 16 Sep 2005 07:52:19 GMT
On fre, 2005-09-16 at 02:33, firstname lastname wrote:
> I need a simple but complete example of how to insert a CLOB into derby
> via jdbc.
> Any help would be appreciated.


    public static void setClobMaxLength(PreparedStatement s, int
fieldNum,
                                        String contents, long maxSize,
                                        Object o, String fieldName)
            throws SQLException {
        if (contents != null) {
            if (contents.length() > maxSize) {
                throw new PermissionDenied(fieldName + " of " + o
                        + " is longer than " + maxSize + " characters");
            }
            s.setCharacterStream(fieldNum, new StringReader(contents),
                    contents.length());
            s.setString(fieldNum, contents);
        } else {
            s.setNull(fieldNum, Types.CLOB);
        }
    }

Here's how you set the contents.  The rest is identical to inserting
other things.

-Lars


Mime
View raw message