2个回答
展开全部
public void save(String vid,String title,String type,String user,String date,String context,String file) throws Exception
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = "insert into news(v_id,title,type,person,inputtime,context,attach_docid) values('"+vid+"','"+title+"','"+type+"','"+user+"','"+date+"',EMPTY_BLOB(),'"+file+"')";
try {
DBJdbc dbjdbc = new DBJdbc();
conn = dbjdbc.getDBConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
String sql1 = "select context from news where v_id ='"+vid+"' for update"; // 使用"FOR UPDATE"得到表的写锁
rs = stmt.executeQuery(sql1);
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob(1); // 得到BLOB对象
OutputStream outout = blob.getBinaryOutputStream(); // 建立输出流
InputStream in = new ByteArrayInputStream(strss.HTMLEncode(context).getBytes()); //字符串转换为数据流
int size = blob.getBufferSize();
byte[] buffer = new byte[size]; // 建立缓冲区
int len;
while ((len = in.read(buffer)) != -1)
outout.write(buffer, 0, len);
in.close();
outout.close();
}
conn.commit();
stmt.close();
conn.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
希望能帮助到你
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String sql = "insert into news(v_id,title,type,person,inputtime,context,attach_docid) values('"+vid+"','"+title+"','"+type+"','"+user+"','"+date+"',EMPTY_BLOB(),'"+file+"')";
try {
DBJdbc dbjdbc = new DBJdbc();
conn = dbjdbc.getDBConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement();
stmt.executeUpdate(sql);
String sql1 = "select context from news where v_id ='"+vid+"' for update"; // 使用"FOR UPDATE"得到表的写锁
rs = stmt.executeQuery(sql1);
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob(1); // 得到BLOB对象
OutputStream outout = blob.getBinaryOutputStream(); // 建立输出流
InputStream in = new ByteArrayInputStream(strss.HTMLEncode(context).getBytes()); //字符串转换为数据流
int size = blob.getBufferSize();
byte[] buffer = new byte[size]; // 建立缓冲区
int len;
while ((len = in.read(buffer)) != -1)
outout.write(buffer, 0, len);
in.close();
outout.close();
}
conn.commit();
stmt.close();
conn.close();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
希望能帮助到你
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用byte类型
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询