Java怎样能把Oracle的Blob类型的内容导出到本地?假如里面存到是文件.
解决方案 »
- servlet怎么发送zip文件到java客户端?
- 关于Hibernate函数问题,高手来看看!
- jsp for循环使用> 的问题
- 为什么我上传了资源后,在我的资源中看不到呀,是不是每个用户有资源的限制呀,
- 请问;学习JSP SERVLET 哪本书比较好,要中文的
- android的相关问题。线程里面出现提示框。
- [200分]一(userinfo)对多(zhaohao)关系的cmp中,为什么在调用zhaohao这个cmp中的create(int zhid,int uid)建立新实例时老是报错错误
- Help me ! 一个新手J2EE中的各种名词的疑惑。
- 持久性框架的选择---你了解持久性框架么?进来看看
- 大家来讨论一下,关于j2ee
- dwr comet 异步问题
- myeclipse 添加Spring支持删除后怎么再添加一次
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/clob10g/handlingclobsinoraclejdbc10g.html
oracle 官方文件 LOB sample
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html
private static byte[] getBlobData(Blob blob) throws SQLException {
byte[] content = new byte[(int) blob.length()];
InputStream in = null;
try {
in = blob.getBinaryStream();
int bytes = in.read(content, 0, (int) blob.length());
if (bytes != blob.length()) {
throw new SQLException("JDBCUtil.getBlobData failed, read " + bytes + " bytes, expected "
+ blob.length());
}
}
catch (IOException e) {
throw new SQLException("JDBCUtil.getBlobData failed: " + e.getMessage());
}
finally {
if (in != null) {
try {
in.close();
}
catch (IOException e) {
// ignore
e.printStackTrace();
}
}
}
return content;
}
* 读出数据并存成文件
*
* @param id
* @param file
*/
public static void readClobDataUseSQL(Integer id, File file) {
Connection conn = getConnection();
try {
Statement st = conn.createStatement();
String sql = "select CONTENT from TEST_CLOB where ID = " + id;
ResultSet rs = st.executeQuery(sql);
if (rs.next()) {
CLOB clob = (CLOB) rs.getClob("CONTENT");
String result = convertClobToString(clob);
System.out.println(result);
FileUtils.writeStringToFile(file,result, "utf-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}