dbutils實現clob和blob存儲

jopen 12年前發布 | 21K 次閱讀 持久層框架 DbUtils

   //使用dbutils實現大文本對象的存儲.
    @Test
    public void testClob() throws Exception{
        String sql="insert into article (content)values(?)";
        File file=new File("bin/stylesheet.css");
        char[] c=new char[(int)file.length()];
        FileReader reader=new FileReader(file);
        reader.read(c);
        SerialClob clob=new SerialClob(c);
        QueryRunner runner=new QueryRunner(JDBCUtils.getDataSource());
        runner.update(sql, clob);

}
//使用dbutils實現二進制對象的存儲.
@Test
public void testBlob() throws Exception{
    String sql="insert into image (content)values(?)";
    File file=new File("bin/bg.jpg");
    byte[] b=new byte[(int)file.length()];
    InputStream in=new FileInputStream(file);
    in.read(b);
    SerialBlob blob=new SerialBlob(b);
    QueryRunner runner=new QueryRunner(JDBCUtils.getDataSource());
    runner.update(sql,blob);
}</pre><br />
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!