package com.abin.struts2.excel;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.struts2.ServletActionContext;
import com.abin.connect.oracle.DBClassConnection;
import com.opensymphony.xwork2.ActionSupport;
public class CreateExcel extends ActionSupport{
private static final int BUFFER_SIZE=16*1024;
private File file;
private String fileFileName;
private String fileContentType;
private String savePath;
private String remarks;
public String FileUpload(){
Connection conn=null;
CallableStatement cs=null;
PreparedStatement ps=null;
ResultSet rs=null;
Calendar cal=Calendar.getInstance();
String suffix=fileFileName.substring(fileFileName.lastIndexOf("."));
long systime=cal.getTimeInMillis();
String filename=systime+suffix;
String path=ServletActionContext.getServletContext().getRealPath(getSavePath())+"\\"+filename;
File outpath=new File(path);
java.sql.Timestamp time=new java.sql.Timestamp(new java.util.Date().getTime());
int returnid=0;
HttpServletRequest request=ServletActionContext.getRequest();
if(fileFileName!=null){
try{
copyFile(file,outpath);
conn=DBClassConnection.getOracle();
cs=conn.prepareCall("{call filepath(?,?,?,?,?,?)}");
cs.setInt(1, 1);
cs.setTimestamp(2, time);
cs.setString(3, path);
cs.setString(4, filename);
cs.setString(5, remarks);
cs.registerOutParameter(6, java.sql.Types.INTEGER);
cs.execute();
returnid=cs.getInt(6);
System.out.println("returnid="+returnid);
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(cs!=null){
cs.close();
}
if(conn!=null){
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
String sql="insert into FILEEXCEL (id,createtime,filepath,filename,remarks) values (?,?,?,?,?)";
try{
conn=DBClassConnection.getOracle();
ps=conn.prepareStatement(sql);
Workbook book=Workbook.getWorkbook(new File(path));
Sheet st=book.getSheet(0);
int row=st.getRows();
int col=st.getColumns();
for(int i=2;i<row-2;i++){
for(int j=0;j<col;j++){
Cell cell=st.getCell(j,i);
String content=cell.getContents();
ps.setString(j+1, content);
}
ps.addBatch();
if(i==10000){
ps.executeBatch();
}
}
ps.executeBatch();
if(book!=null){
book.close();
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(conn!=null){
conn.close();
}
if(ps!=null){
ps.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
fileBean bean=new fileBean();
List<fileBean> list=new ArrayList<fileBean>();
try{
conn=DBClassConnection.getOracle();
cs=conn.prepareCall("{call fileout(?,?)}");
cs.setInt(1, returnid);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
rs=(ResultSet)cs.getObject(2);
while(rs.next()){
bean.setId(rs.getInt("id"));
bean.setCreatetime(rs.getTime("createtime"));
bean.setFilepath(rs.getString("filepath"));
bean.setFilename(rs.getString("filename"));
bean.setRemarks(rs.getString("remarks"));
list.add(bean);
}
}catch(Exception e){
e.printStackTrace();
}
request.getSession().setAttribute("list", list);
return SUCCESS;
}else{
return ERROR;
}
}
public void copyFile(File from,File to){
InputStream in=null;
OutputStream out=null;
try{
in=new BufferedInputStream(new FileInputStream(from),BUFFER_SIZE);
out=new BufferedOutputStream(new FileOutputStream(to),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
while(in.read(buffer)>0){
out.write(buffer);
out.flush();
}
}catch(Exception e){
e.printStackTrace();
}
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Struts2 Excel导入导出数据
共67个文件
jar:25个
java:12个
class:12个
4星 · 超过85%的资源 需积分: 9 76 下载量 149 浏览量
2011-10-05
00:01:44
上传
评论 4
收藏 14.34MB RAR 举报
温馨提示
Struts2 从Oracle导出数据到Excel,建表语句,存储过程语句,都有
资源推荐
资源详情
资源评论
收起资源包目录
better.rar (67个子文件)
better
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 107B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 500B
org.eclipse.jdt.core.prefs 330B
src
com
abin
test
BaseTest.java 613B
CoreoneTest.java 778B
connect
oracle
DBClassDbtwo.java 4KB
DBClassConnection.java 4KB
DBClassMysql.java 4KB
clob
Clob.java 915B
procedure
BaseBean.java 885B
BaseResult.java 2KB
struts2
excel
CreateExcel.java 5KB
ExcelFromOracle.java 2KB
Excel.java 2KB
fileBean.java 883B
struts.xml 785B
.project 1KB
WebRoot
use.sql 842B
image
META-INF
MANIFEST.MF 36B
WEB-INF
web.xml 977B
classes
com
abin
test
BaseTest.class 1KB
CoreoneTest.class 2KB
connect
oracle
DBClassMysql.class 4KB
DBClassDbtwo.class 4KB
DBClassConnection.class 4KB
clob
Clob.class 2KB
procedure
BaseBean.class 1KB
BaseResult.class 3KB
struts2
excel
ExcelFromOracle.class 3KB
Excel.class 3KB
CreateExcel.class 7KB
fileBean.class 1KB
struts.xml 785B
lib
commons-codec-1.3.jar 46KB
commons-logging-1.0.4.jar 37KB
proxool-0.9.0RC3.jar 430KB
log4j-1.2.16.jar 470KB
htmlparser.jar 136KB
standard.jar 384KB
ojdbc14.jar 1.47MB
commons-httpclient-3.1.jar 298KB
xwork-2.1.2.jar 2.18MB
zsUtility.jar 23KB
db2jcc.jar 3.08MB
pams3-tpui-client.1.0.jar 8KB
ognl-2.6.11.jar 164KB
jstl.jar 20KB
mysql-connector-java-5.1.15-bin.jar 768KB
commons-fileupload-1.2.1.jar 56KB
struts2-convention-plugin-2.1.6.jar 61KB
struts2-core-2.1.6.jar 2.2MB
commons-io-1.3.2.jar 86KB
freemarker-2.3.13.jar 850KB
struts2-dojo-plugin-2.1.6.jar 1.65MB
xpp3_min-1.1.4c.jar 24KB
xstream-1.3.1.jar 421KB
jxl.jar 708KB
htmllexer.jar 70KB
index.jsp 834B
excel
export.jsp 483B
exportsuccess.jsp 467B
index.jsp 699B
success.jsp 1KB
.mymetadata 291B
.classpath 2KB
.myeclipse
共 67 条
- 1
varyall
- 粉丝: 1140
- 资源: 269
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页