package net.company.dao;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import net.company.connect.ConnCOnnection;
import net.company.dto.Student;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class Date {
public void getDate()
{
List liststu=new ArrayList();
// 找到导入的文件
InputStream is= Date.class.getClassLoader().getResourceAsStream("student.xls");
try {
//创建工作簿
Workbook wb=Workbook.getWorkbook(is);
//创建工作表
jxl.Sheet sheet=wb.getSheet(0);
String content=null;
for(int i=1;i<sheet.getRows();i++)
{
Student stu=new Student();
for(int j=0;j<sheet.getColumns();j++)
{
content=sheet.getCell(j, i).getContents();
//j代表列 从0开始
//i代表行 从1开始
System.out.println(j+"----"+i);
System.out.print(content);
if(stu.getId()==0)
{
stu.setId(Integer.parseInt(sheet.getCell(j, i).getContents()));
continue;
}
if(stu.getName()==null)
{
stu.setName(sheet.getCell(j, i).getContents());
continue;
}
if(stu.getAge()==0)
{
stu.setAge(Integer.parseInt(sheet.getCell(j, i).getContents()));
continue;
}
}
getStudentInfo(stu);
}
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void getStudentInfo(Student stu)
{
String sql="insert into stu values("+stu.getId()+",'"+stu.getName()+"',"+stu.getAge()+")";
ConnCOnnection conn=new ConnCOnnection();
Connection con=conn.getConnect();
try {
Statement state=con.createStatement();
state.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Excel导入导出MYSQL,0分下载
5星 · 超过95%的资源 需积分: 15 142 浏览量
2011-11-21
22:36:49
上传
评论
收藏 822KB RAR 举报
聪明一休
- 粉丝: 1
- 资源: 19
最新资源
- 传统网页UI设计在移动应用开发中的应用研究.pdf
- 基于pytorch实现BERT+BiLSTM+CRF实现中文命名实体识别源码.zip
- 校园帮项目,毕业设计/课程设计/javaWeb/SSM
- C++ plotting library,matplotlib-cpp-master.zip
- 案例源码matplotlib-examples-master.zip
- 基于JavaScript 实现的KMP 算法
- 基于C++实现二叉树的创建,遍历,添加,查找与删除
- 基于C语言实现二叉树的基本操作
- 毕业设计基于STM32的测量温度与压力的数据处理设计C语言完整源码+论文.zip
- 基于MATLAB的PCA算法人脸识别项目源码+GUI界面+说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页