Blob新增保存例子代码如下:
public void testSaveBLob() throws BusinessException { Lobtest lob = new Lobtest(); long id = 1L, start = System.currentTimeMillis(), end; String file = "e:\\MyProjects\\test.rar"; lob.setTid(id); try { InputStream is = new FileInputStream(new File(file)); byte[] bytes = IOUtility.toByteArray(is);is.close(); lob.setTblob(bytes);
DBAgent.save(lob);
end = System.currentTimeMillis(); System.out.println("Saved:" + (end - start)); } catch (Exception e) { e.printStackTrace(); } }
Blob读取和更新例子代码如下:
public void testGetAndUpdateBLob() throws BusinessException { Lobtest lob = new Lobtest(); long id = 1L, start = System.currentTimeMillis(), end; String file = "e:\\MyProjects\\test.rar"; String ofile = "e:/test.rar"; lob.setTid(id); try { lob = (Lobtest) DBAgent.get(Lobtest.class, id); byte[] bytes = lob.getTblob();OutputStream os = new FileOutputStream(new File(ofile)); IOUtility.copy(bytes, os); os.flush(); os.close(); end = System.currentTimeMillis(); System.out.println("Readed:" + (end - start)); start = end; InputStream is = new FileInputStream(new File(file)); bytes = IOUtility.toByteArray(is); is.close(); lob.setTblob(bytes);
DBAgent.update(lob);
end = System.currentTimeMillis(); System.out.println("Updated:" + (end - start)); start = end; } catch (Exception e) { e.printStackTrace(); } }
Clob新增保存例子代码如下:
public void testSaveCLob() throws BusinessException { long id = 2L, size = 100000, start = System.currentTimeMillis(), end; Lobtest lob = new Lobtest(); lob.setTid(id); StringBuffer sb = new StringBuffer((int) size); for (int i = 0; i < size; i++) sb.append('a'); lob.setTclob(sb.toString());DBAgent.save(lob);
end = System.currentTimeMillis(); System.out.println("Saved:" + (end - start)); }
Clob读取和更新例子代码如下:
public void testGetAndUpdateCLob() throws BusinessException { long id = 2L, size = 100000, start = System.currentTimeMillis(), end; Lobtest lob = (Lobtest) DBAgent.get(Lobtest.class, id); end = System.currentTimeMillis(); System.out.println("Readed:" + lob.getTclob().length() + ":" + (end - start));start = end; StringBuffer sb = new StringBuffer((int) size); for (int i = 0; i < size; i++) sb.append('b'); lob.setTclob(sb.toString());
DBAgent.update(lob);
System.out.println("Updated:" + (end - start)); start = end; }