各位大虾,如何将execl导入到sql中哈?

lihao1129 2009-08-25 11:26:42
表名hdmain
private Integer mainId;//主键自动增长列
private ArticleId articleId;//外键
private Hddate hddate;//外键
private Corporation corporation;//外键
private String mainManhourTest;
private String mainManhourRepair;
private String mainManhourOverhaul;
private String mainImmobilityRepair;
private String mainImmobilityOverhaul;
private String mainWarrantyTime;
private String mainCycle;

表名hddate
private Integer dateId;
private String dateData;

表名corporation
private Integer corporationId;
private String corporationName;

表名articleId
private Integer articleIdId;
private String articleIdName;
private String articleIdAta;

页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>


<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'showlist.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="CSS/table.css" type="text/css">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/interface/service.js"></script>

<script type="text/javascript" src="js/comm.js"></script>
<script type="text/javascript">
var num = 1;
     function addFile(){
     num++;
     var obj=document.getElementById("uploadFile");
     var innerHTML=obj.innerHTML;
     var insertHTML= "文件"+num+":<input type='file' name='testFile["+num+"]' size='30'/> <br> ";
     innerHTML=innerHTML+insertHTML;
     //alert(innerHTML);
     obj.innerHTML=innerHTML;
     }
function upload(){
document.forms[0].action+="?method=upload";
document.forms[0].submit();
}

function toAdd(){
document.forms[0].action+="?method=toAdd";
document.forms[0].submit();
}
function dolist(){
document.forms[0].action+="?method=list";
document.forms[0].submit();
}
function toDel(id)
{
document.forms[0].action+="?method=toDelete&id="+id;
document.forms[0].submit();
}
function toUpdate(id)
{
document.forms[0].action+="?method=toUpdate&id="+id;
document.forms[0].submit();
}
</script>
</head>



<body>
<html:form method="post" action="main.do" enctype="multipart/form-data">
<!-- -->

<table width="100%">
<tr>
<td>
<font color="#0000CC">您正在做的业务是:数 据</font>
</td>
</tr>
</table>
<table >
<tr>
<td>公司名称:<input type="text" name="hdCorporation"></td>
<td>件 号:<input type="text" name="hdarticleId"></td>
<td>章节号:<input type="text" name="hdATA"></td>
<td><input type="button" value="添加" onclick="javascript:toAdd();"></input></td>
<td><input type="button" value="查询" onclick="javascript:dolist();"/></td>
</tr>
</table>
<table border="1" width="80%" align="center" >
<TBODY class="TD_STYLE1">
<TR>
<td colspan="2" align="center">
<span id="uploadFile">
文件1:<input type="file" name="testFile[1]" size="30"/><br>
</span>
</td>
</TR>
<TR>
<td align="center">
<input type="button" name="btnAddFile" value="添加文件"
onclick="addFile()"/>
</td>
<TD align="center">
<input type="submit" name="btnUpload" value="上传文件" onclick="upload();"/>
</TD>
</TR>
</TBODY>
</table>
<table width="100%" border="1" cellpadding=0 cellspacing=1
bordercolorlight=#848284 bordercolordark=#eeeee class="TABLE_STYLE1">

<tr align="center">
<td width="8%" class="TD_STYLE1">公司名称</td>
<td width="8%" class="TD_STYLE1">ATA章节号</td>
<td width="12%" class="TD_STYLE1">件号</td>
<td width="8%" class="TD_STYLE1">测试(工时)</td>
<td width="8%" class="TD_STYLE1">修理(工时)</td>
<td width="8%" class="TD_STYLE1">翻修(工时)</td>
<td width="8%" class="TD_STYLE1">修理(固定)</td>
<td width="8%" class="TD_STYLE1">翻修(固定)</td>
<td width="8%" class="TD_STYLE1">保修期</td>
<td width="8%" class="TD_STYLE1">周期</td>
<td width="8%" class="TD_STYLE1">报价日期</td>
<td width="8%" class="TD_STYLE1">操作</td>
</tr>

<logic:iterate name="pb" id="list" property="currentList">
<tr align="center" class="TD_STYLE2">
<td>${list.corporation.corporationName}</td>
<td>${list.articleId.articleIdAta}</td>
<td>${list.articleId.articleIdName}</td>
<td>${list.mainManhourTest}</td>
<td>${list.mainManhourRepair}</td>
<td>${list.mainManhourOverhaul}</td>
<td>${list.mainImmobilityRepair}</td>
<td>${list.mainImmobilityOverhaul}</td>
<td>${list.mainWarrantyTime}</td>
<td>${list.mainCycle}</td>
<td>${list.hddate.dateData}</td>
<td>
<a href="javascript:toUpdate('${list.mainId}');">更新</a>
<a href="javascript:toDel('${list.mainId}');">删除</a>
</td>
</tr>
</logic:iterate>
</table>

<table align="center" class="TD_STYLE9">
<tr>
<td>
总记录数${pb.allRecord}条记录,总页数有${pb.allPage}页,当前是${pb.currentPage}页
从第${pb.first+1}条记录到第${pb.last+1}条记录
</td>
</tr>
<tr>
<td>
<logic:equal value="1" name="pb" property="currentPage">
首页 上一页
</logic:equal>
<logic:greaterThan value="1" name="pb" property="currentPage">
<a href="main.do?method=list&page=1">首页</a>
<a href="main.do?method=list&page=${pb.currentPage-1}">上一页</a>
</logic:greaterThan>
<logic:equal value="${pb.allPage}" name="pb" property="currentPage">
下一页 尾页
</logic:equal>
<logic:lessThan value="${pb.allPage}" name="pb" property="currentPage">
<a href="main.do?method=list&page=${pb.currentPage+1}">下一页</a>
<a href="main.do?method=list&page=${pb.allPage}">尾页</a>
</logic:lessThan>

<input type="text" name="page" size="2">
<input type="button" value="转到">

<a href="index.jsp">返回</a>
</td>
</tr>
</table>
</html:form>
</body>

</html>


我这 怎么样 才能 把execl 文件导入到sql里面呢?
...全文
140 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuyx808 2009-08-26
  • 打赏
  • 举报
回复
是sqlserver就好办了,打开你的查询分析器,选择一个表,右键,导入数据,然后下一步,选择excel类型的……一直界面操作啊
lihao1129 2009-08-26
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 zhuyx808 的回复:]
如果数据库是mssqlserver 的话,数据库本身就有一功能是从execl直接导入数据库的,或者从数据库直接导出到execl的
[/Quote]
sql server2005? 我找了半天 都没有找到 都是些自动 生成的 语句

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
String encoding = request.getCharacterEncoding();
if((encoding!=null)&&(encoding.equalsIgnoreCase("utf-8"))){
response.setContentType("text/html; charset=gb2312");//如果没有指定编码,编码格式为gb2312
}
UploadForm uf = (UploadForm) form;
ExeclFiliter execlFiliter = new ExeclFiliter();
FormFile file = uf.getTheFile();//取得上传的文件
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.out.println("获取到的文件:"+file);
try {
String filePath = this.getServlet().getServletContext().getRealPath("/");

file.getInputStream();//把文件读入
System.out.println(filePath + "/"+ file.getFileName());
System.out.println(filePath +"UploadFiles\\"+file.getFileName());
new FileOutputStream(filePath +"UploadFiles\\"+file.getFileName());
System.out.println("『『『『『『『『『『『『『");
execlFiliter.intoExecl(filePath +"UploadFiles\\"+file.getFileName());

} catch (Exception e) {
// TODO: handle exception
}
return mapping.findForward("Add_success");
}

为什么我执行到new FileOutputStream(filePath +"UploadFiles\\"+file.getFileName());
路径下 生成 这个文件...怎么回事哈
zhuyx808 2009-08-26
  • 打赏
  • 举报
回复
如果数据库是mssqlserver 的话,数据库本身就有一功能是从execl直接导入数据库的,或者从数据库直接导出到execl的
lihao1129 2009-08-26
  • 打赏
  • 举报
回复
我获取的路径有问题哈,有没有人能继续帮下我...
closewbq 2009-08-25
  • 打赏
  • 举报
回复
http://wangchao0605.javaeye.com/blog/454417
http://zhidao.baidu.com/question/89483557.html
zjx2388 2009-08-25
  • 打赏
  • 举报
回复
提供思路,具体的代码不给你写

用POI或者JXL操作excel,先取出excel中的数据,然后通过SQL语句插入到数据库中
jxl官方API:
http://jexcelapi.sourceforge.net/
youdandan 2009-08-25
  • 打赏
  • 举报
回复
學習一下哦
kbyst 2009-08-25
  • 打赏
  • 举报
回复
这个导入是指?

如果是数据就使用POI取到Excel的数据
再从java中导入数据库

这有个老贴,楼主看看能不能帮到你
http://topic.csdn.net/t/20050115/16/3728365.html
lihao1129 2009-08-25
  • 打赏
  • 举报
回复
那这个路径如何获取呢?因为 我actionForm都用上了,从新写了form

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧