
参考代码如下:
public class InsertBlobData {
Connection con = null;
/
@param args
@throws Exception
/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
InsertBlobData data = new InsertBlobData();
datainsertBlogInfo("002jpg", "sdsdfdf", "2007-02-12", "002jpg");
}
public void insertBlogInfo(String jmzh, String xm, String smsj,
String fileName) throws Exception {
// try {
con = ConnectionPoliceFactorygetFactory()getConnection();
// } catch (ClassNotFoundException e) {
// // TODO Auto-generated catch block
// eprintStackTrace();
// }
// 处理事务
boolean defaultCommit = congetAutoCommit();
consetAutoCommit(false);
Statement st = concreateStatement();
// 插入一个空对象
stexecuteUpdate("insert into ksren_txxx(jmzh,xm,smsj,txsj) values('"
+ jmzh + "','" + xm + "',to_date('" + smsj
+ "','yyyy-mm-dd'),empty_blob())");
// 用for update方式锁定数据行
ResultSet rs = st
executeQuery("select txsj from ksren_txxx where jmzh='"
+ jmzh + "' and xm='" + xm + "' for update");
if (rsnext()) {
// 得到javasqlBlob对象,然后Cast为oraclesqlBLOB
oraclesqlBLOB blob = (oraclesqlBLOB) rsgetBlob(1);
// 到数据库的输出流
OutputStream outStream = blobgetBinaryOutputStream();
// 这里用一个文件模拟输入流
InputStream fin = new FileInputStream(new File(fileName));
// 将输入流写到输出流
byte[] b = new byte[blobgetBufferSize()];
int len = 0;
while ((len = finread(b)) != -1) {
outStreamwrite(b, 0, len);
// blobputBytes(1,b);
}
// 依次关闭(注意顺序)
finclose();
outStreamflush();
outStreamclose();
concommit();
/ 恢复原提交状态 /
consetAutoCommit(defaultCommit);
conclose();
}
}
}
既然考虑到 安全问题,那么在客户端实现确实是不安全的。
在服务器端实现很简单呀
首先,保存文件的过程估计你已经写好了,那么文件名等信息应该也获取到了。
服务器端实现连接自己的数据库,然后执行sql就好了呀。
当然还有一种实现,就是由客户端拼sql,当作一个字符串传给服务器端,由服务器端去执行。几乎所有的界面化数据库连接工具都是这样做的,主要是因为sql是人现场录入的。
以上就是关于java存储富文本到什么数据库全部的内容,包括:java存储富文本到什么数据库、如何用java向数据库中存储大量文字、JAVA中存文件到ORACLE数据库里怎么做等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)