`
king_tt
  • 浏览: 2122836 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

DButils实现clob和blob存储

 
阅读更多
//使用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);
 }


转自网络,原作者佚名

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics