java中如何将图片存入到oracle数据库并读出来 我知道用数据流的方式把图片弄成二进制形式存入到数据库 但是我不知道该怎么去写这个东西 希望各位能帮帮我 谢谢 最好给个例子 可以研究研究 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你贴一个吧,刚做的public static void insertBlob(Connection conn, byte[] data, String tableName, String keyName, String blobName, String colKey) { Statement stmt = null; ResultSet result = null; boolean defaultCommit = false; OutputStream outStream = null; /* 设置为不能自动提交 */ try { defaultCommit = conn.getAutoCommit(); conn.setAutoCommit(false); StringBuffer QuerySQL = new StringBuffer(); StringBuffer EmptyQuerySQL = new StringBuffer(); StringBuffer chekexistSQL = new StringBuffer(); StringBuffer UptdateSQL = new StringBuffer(); stmt = conn.createStatement(); chekexistSQL.append("SELECT * FROM ").append(tableName).append( " WHERE ").append(colKey).append("=").append("'").append( keyName).append("'"); EmptyQuerySQL.append("INSERT INTO ").append(tableName).append("(") .append(colKey).append(",").append(blobName).append( ") VALUES (").append("'").append(keyName).append( "',empty_blob()").append(")"); UptdateSQL.append("UPDATE ").append(tableName).append(" SET ") .append(blobName).append("=empty_blob() where ").append(colKey).append("='").append(keyName).append("'"); QuerySQL.append("SELECT ").append(blobName).append(" FROM ") .append(tableName).append(" ").append(" WHERE ").append( colKey).append("=").append("'").append(keyName) .append("'").append(" FOR UPDATE"); result = stmt.executeQuery(chekexistSQL.toString()); if (!result.next()) { /* 插入空的附件 sql 中包含empty_blob() */ stmt.executeUpdate(UptdateSQL.toString()); } else { stmt.executeUpdate(EmptyQuerySQL.toString()); } /* 查询此BLOB对象并锁定 */ result = stmt.executeQuery(QuerySQL.toString()); if (result.next()) { oracle.sql.BLOB blob = (oracle.sql.BLOB) result .getBlob(blobName); outStream = blob.getBinaryOutputStream(); // data是传入的byte数组,定义:byte[] data outStream.write(data, 0, data.length); outStream.flush(); } else { // log.info("没有找到数据result=" + result.toString()); } /* 正式提交 */ conn.commit(); } catch (IOException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } catch (SQLException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } finally { try { if (outStream != null) outStream.close(); } catch (IOException e1) { // TODO 自动生成 catch 块 } try { if (result != null) result.close(); } catch (SQLException e) { // log.debug("close result Exception"); } try { if (stmt != null) stmt.close(); } catch (SQLException e) { // log.debug("close stmt Exception"); } try { if (conn != null) conn.setAutoCommit(defaultCommit); } catch (SQLException e) { // log.debug("close conn Exception"); } // log.debug("finally!end"); } } 其中data为你读取的前台图片的数据 很完整的代码http://blog.csdn.net/caoyinghui1986/archive/2008/04/05/2252772.aspx包括存储和读取。 网站访问量怎么实现 求教各位大虾,用java语言如何将html文档转换为jpg图片? JSP 网页制作方面的问题... 飞鱼编辑器的问题 这样会出错,如何改啊? 一个初学者的问题 spring3+security3+struts2开源权限项目(有效果图) 怪!common.upload到了这一句就出错! 请教:struts中jsp页面问题 =====SERVLET的问题----请教高人帮忙解决-----报酬1000RMB 怎么取list里面的值啊? 怎么用java导出excel文件
public static void insertBlob(Connection conn, byte[] data,
String tableName, String keyName, String blobName, String colKey) {
Statement stmt = null;
ResultSet result = null;
boolean defaultCommit = false;
OutputStream outStream = null;
/* 设置为不能自动提交 */
try {
defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false); StringBuffer QuerySQL = new StringBuffer();
StringBuffer EmptyQuerySQL = new StringBuffer();
StringBuffer chekexistSQL = new StringBuffer();
StringBuffer UptdateSQL = new StringBuffer();
stmt = conn.createStatement(); chekexistSQL.append("SELECT * FROM ").append(tableName).append(
" WHERE ").append(colKey).append("=").append("'").append(
keyName).append("'"); EmptyQuerySQL.append("INSERT INTO ").append(tableName).append("(")
.append(colKey).append(",").append(blobName).append(
") VALUES (").append("'").append(keyName).append(
"',empty_blob()").append(")"); UptdateSQL.append("UPDATE ").append(tableName).append(" SET ")
.append(blobName).append("=empty_blob() where ").append(colKey).append("='").append(keyName).append("'"); QuerySQL.append("SELECT ").append(blobName).append(" FROM ")
.append(tableName).append(" ").append(" WHERE ").append(
colKey).append("=").append("'").append(keyName)
.append("'").append(" FOR UPDATE"); result = stmt.executeQuery(chekexistSQL.toString());
if (!result.next()) {
/* 插入空的附件 sql 中包含empty_blob() */
stmt.executeUpdate(UptdateSQL.toString());
} else {
stmt.executeUpdate(EmptyQuerySQL.toString());
} /* 查询此BLOB对象并锁定 */
result = stmt.executeQuery(QuerySQL.toString());
if (result.next()) {
oracle.sql.BLOB blob = (oracle.sql.BLOB) result
.getBlob(blobName);
outStream = blob.getBinaryOutputStream();
// data是传入的byte数组,定义:byte[] data
outStream.write(data, 0, data.length);
outStream.flush();
} else {
// log.info("没有找到数据result=" + result.toString());
}
/* 正式提交 */
conn.commit(); } catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally {
try {
if (outStream != null)
outStream.close();
} catch (IOException e1) {
// TODO 自动生成 catch 块
}
try {
if (result != null)
result.close();
} catch (SQLException e) {
// log.debug("close result Exception");
}
try {
if (stmt != null)
stmt.close();
} catch (SQLException e) {
// log.debug("close stmt Exception");
}
try {
if (conn != null)
conn.setAutoCommit(defaultCommit);
} catch (SQLException e) {
// log.debug("close conn Exception");
}
// log.debug("finally!end");
}
}
http://blog.csdn.net/caoyinghui1986/archive/2008/04/05/2252772.aspx
包括存储和读取。