<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import="java.lang.*,java.io.*,java.sql.*,java.util.*" %>
<%@ page import="jxl.* " %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//1.加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.找开连接
String OracleURL = "jdbc:oracle:thin:@192.168.4.202:1521:ujpcn";
Connection conn=DriverManager.getConnection(OracleURL,"netcool","netcool");
//xxxx这里是数据库的用户名,****这里是数据库的密码。
//3.创建statement
Statement stat=conn.createStatement();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<lable>
<div align="center">导入收信人联系方式
<input name="file" type="file" size="40" />
<input type="submit" name="Submit6" value="导入" />
</div>
</lable>
</form>
</body>
</html>
要求是导入一个EXECL里的数据然后写入ORACLE。。
EXECL里数据是
1 2
2 3
3 4
数据库里也是2个字段这个应该怎么改法?哪位大大可以帮我修改一下
<%@ page import="java.lang.*,java.io.*,java.sql.*,java.util.*" %>
<%@ page import="jxl.* " %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";//1.加载驱动
Class.forName("oracle.jdbc.driver.OracleDriver");
//2.找开连接
String OracleURL = "jdbc:oracle:thin:@192.168.4.202:1521:ujpcn";
Connection conn=DriverManager.getConnection(OracleURL,"netcool","netcool");
//xxxx这里是数据库的用户名,****这里是数据库的密码。
//3.创建statement
Statement stat=conn.createStatement();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<lable>
<div align="center">导入收信人联系方式
<input name="file" type="file" size="40" />
<input type="submit" name="Submit6" value="导入" />
</div>
</lable>
</form>
</body>
</html>
要求是导入一个EXECL里的数据然后写入ORACLE。。
EXECL里数据是
1 2
2 3
3 4
数据库里也是2个字段这个应该怎么改法?哪位大大可以帮我修改一下
<%@ include file="../../common/checkuser.jsp"%>
<%@ include file="../../common/linkdbcommon.jsp"%>
<%@ page import="javax.naming.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="java.io.*,jxl.Workbook,jxl.*;" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<%
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
com.jspsmart.upload.File myFile = null;
String strResinMulu=request.getRealPath("/upload");
java.io.File dir = new java.io.File(strResinMulu);
if(! dir.exists())
{
dir.mkdir();
}
myFile = mySmartUpload.getFiles().getFile(0);
mySmartUpload.save(strResinMulu);
String strgetExcelpath=strResinMulu+"\\"+myFile.getFileName();
jxl.Workbook wb = null;
try {
//构造Workbook(工作薄)对象
wb=jxl.Workbook.getWorkbook(new java.io.File(strgetExcelpath));
} catch (Exception e) {
//out.print(e.printStackTrace());
e.printStackTrace();
}
Sheet sheet = wb.getSheet(0);
int rowcnt = sheet.getRows();
//int intcol=sheet.getColumns();
String tempValue="";
String tempValue1="";
String str="";
String str1="";
String regex = "\\d+";
String s_class ="";
String syear="";
String sterm="";
int iii=0;
sql = "";
int jjj=0;
for(int i = 1 ; i < rowcnt ; i++){
tempValue="";
if(sheet.getCell(1,i).getContents()!=""&&sheet.getCell(1,i).getContents()!=null){
iii++;
syear=sheet.getCell(3,i).getContents();
OK!
把excel的东西复制到文本里
在pl/sql里建张表,右键点编辑数据,然后直接粘贴进去就行了
注意表字段和excel的字段要相对应
POIFSFileSystem fs=null;
HSSFWorkbook wb=null;
HSSFSheet sheet=null;
HSSFRow row=null;
try {
fs = new POIFSFileSystem(excelFile.getInputStream());
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
e.printStackTrace();
}
sheet = wb.getSheetAt(0);
//得到总行数
int rowNum = sheet.getLastRowNum();
row = sheet.getRow(0);
// int colNum = row.getPhysicalNumberOfCells();
//正文内容应该从第二行开始,第一行为表头的标题
for (int i = 1; i <= rowNum; i++) {
row = sheet.getRow(i);
String str0=getStringCellValue(row.getCell((short) 0)).trim()
......
}
private String getStringCellValue(HSSFCell cell) {
String strCell = "";
if(cell!=null){
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
strCell = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
strCell = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
strCell = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
strCell = "";
break;
default:
strCell = "";
break;
}
}else{
return "";
}
if (strCell.equals("") || strCell == null) {
return "";
}
if (cell == null) {
return "";
}
return strCell;
}