package com.meritit.fusionchart;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.codec.binary.Hex;
import oracle.sql.BLOB;
/**
* 向oracle 读,写文件Blob
*
* @author guolw
*/
public class OracleBlob {
private String driver = "oracle.jdbc.driver.OracleDriver";
private String url = "";
private String user = "";
private String pwd = "";
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
/**
* 构造函数
*
* @param String
* url 数据库连接字符串
* @param String
* user 数据库用户名
* @param String
* pwd 数据库登录密码
*/
public OracleBlob(String url, String user, String pwd) {
this.url = url;
this.user = user;
this.pwd = pwd;
}
/**默认构造函数*/
public OracleBlob() {
}
/**
* 写二进制文件
*
* @param String
* ID 文件在数据表中唯一ID
* @param String
* filePath 文件路径
* @param Connection conn 数据库连接,如果置为null 则函数生成conn
* @param InputStream inStream 需要写入到数据库的图片流
*/
public void writeBlob(Connection conn, InputStream inStream,
String tableName, String ID, String fileName) {
boolean conFlag = false;// 当前连接是否在方法内生成
try {
// 具体可使用hibernate中的Conn
if (conn == null) {
conFlag = true;
conn = getConnection();
}
boolean defaultCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
String sqlquery = "select IMAGE from " + tableName + " where ID='"
+ ID + "' FOR UPDATE";
ResultSet rs = stmt.executeQuery(sqlquery);
if (rs.next()) {
stmt.executeUpdate("UPDATE " + tableName
+ " SET IMAGE=EMPTY_BLOB() WHERE ID='" + ID + "'");
rs = stmt.executeQuery(sqlquery);
insertClob(rs, inStream);
} else {
StringBuffer sbf = new StringBuffer("insert into " + tableName
+ "(ID,FILE_NAME,IMAGE) values (");
sbf.append("'");
sbf.append(ID);
sbf.append("','");
sbf.append(fileName);
sbf.append("'");
sbf.append(",EMPTY_BLOB())");
stmt.executeUpdate(sbf.toString());
rs = stmt.executeQuery(sqlquery);
insertClob(rs, inStream);
}
conn.commit();
conn.setAutoCommit(defaultCommit);
stmt.close();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
System.out.println(e1.getLocalizedMessage());
}
System.out.println(e.getLocalizedMessage());
} finally {
try {
if (conn != null)
if (conFlag) { // 如果当前连接在方法内生成,则关闭该连接
conn.close();
}
} catch (SQLException e) {
System.out.println(e.getLocalizedMessage());
}
}
}
public String getID() {
return new String(Hex.encodeHex(org.apache.commons.id.uuid.UUID
.randomUUID().getRawBytes()));
}
private void insertClob(ResultSet rs, InputStream inStream) {
try {
if (rs.next()) {
BLOB blob = (BLOB) rs.getBlob("IMAGE");
OutputStream out = blob.getBinaryOutputStream();
int bufferSize = ((oracle.sql.BLOB) blob).getBufferSize();
BufferedInputStream in = new BufferedInputStream(inStream,
bufferSize);
byte[] b = new byte[bufferSize];
int count = in.read(b, 0, bufferSize);
int amount = 0;
while (count != -1) {
out.write(b, 0, count);
amount += count;
count = in.read(b, 0, bufferSize);
}
out.close();
out = null;
in.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private Connection getConnection() {
Connection con = null;
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con = DriverManager.getConnection(url, user, pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public byte[] GetImgByteById(Connection conn, String imageID) {
boolean conFlag = false;// 当前连接是否在方法内生成
byte[] data = null;
try {
if (conn == null) {
conn = this.getConnection();
}
Statement stmt = conn.createStatement();
ResultSet myResultSet = stmt
.executeQuery("select * from FUSIONCHART_IMAGE_TEMP"
+ " where ID='" + imageID+"'");
if (myResultSet.next()) {
java.sql.Blob blob = myResultSet.getBlob("IMAGE");
InputStream inStream = blob.getBinaryStream();
try {
long nLen = blob.length();
int nSize = (int) nLen;
data = new byte[nSize];
inStream.read(data);
inStream.close();
} catch (IOException e) {
System.out.println("获取图片数据失败,原因:" + e.getMessage());
}
}
conn.commit();
if(conFlag){
if(conn!=null){
conn.close();
}
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
return data;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
fc.rar_FCExporter.jsp_FCExporter_PDF.jsp
共42个文件
jsp:11个
xml:8个
jar:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 5 浏览量
2022-09-14
19:28:21
上传
评论
收藏 1.82MB RAR 举报
温馨提示
furtions charts 报表示例
资源推荐
资源详情
资源评论
收起资源包目录
fc.rar (42个子文件)
fc
fc
swf
Pie3D.swf 56KB
FCExporter.swf 20KB
Column2D.swf 54KB
direct_pic.html 873B
FCExporterContentPic.jsp 4KB
META-INF
MANIFEST.MF 39B
FCExporterDirectPic.jsp 7KB
WEB-INF
web.xml 15KB
classes
com
meritit
fusionchart
OracleBlob.class 6KB
lib
commons-logging-1.1.1.jar 59KB
fcexporter.jar 20KB
apache-commons-discovery.jar 70KB
classes12.jar 1.52MB
apache-commons-id.jar 128KB
commons-codec.jar 46KB
only_pic.html 1KB
js
FusionCharts.js 13KB
FusionChartsExportComponent.js 6KB
jquery-1.4.2.min.js 71KB
WordContentPic.jsp 4KB
Resources
FCExporter_IMG.jsp 8KB
FCExporter_PDF.jsp 4KB
FCExporterError.jsp 1022B
FCExporter.jsp 7KB
index.jsp 1KB
word_pic.html 4KB
imageShow.jsp 972B
WordPic.jsp 747B
xml
only_pic.xml 583B
direct_pic.xml 585B
word_pic.xml 591B
word_content_pic_PG0.xml 579B
word_content_pic_PG1.xml 614B
direct_pic1.xml 582B
Copy of word_content_pic.xml 579B
word_content_pic.jsp 3KB
.settings
com.genuitec.eclipse.core.prefs 125B
org.eclipse.core.resources.prefs 424B
src
com
meritit
fusionchart
OracleBlob.java 6KB
.project 1KB
.mymetadata 274B
.classpath 847B
.myeclipse
共 42 条
- 1
资源评论
邓凌佳
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功