• jdbc 的连接
  • 实体类
package com.gpdi.mdata.web.manage.database.data;
public class DBQueryData {
private String url;
private String dbName;
private String user;
private String passwd;
private String tableName;
private String where; public String getUrl() {
return url;
} public void setUrl(String url) {
this.url = url;
} public String getDbName() {
return dbName;
} public void setDbName(String dbName) {
this.dbName = dbName;
} public String getUser() {
return user;
} public void setUser(String user) {
this.user = user;
} public String getPasswd() {
return passwd;
} public void setPasswd(String passwd) {
this.passwd = passwd;
} public String getTableName() {
return tableName;
} public void setTableName(String tableName) {
this.tableName = tableName;
} public String getWhere() {
return where;
} public void setWhere(String where) {
this.where = where;
} @Override
public String toString() {
return "DBQueryData{" +
"url='" + url + '\'' +
", dbName='" + dbName + '\'' +
", user='" + user + '\'' +
", passwd='" + passwd + '\'' +
", tablename='" + tableName + '\'' +
", where='" + where + '\'' +
'}';
}
}

  • JDBC封装

package com.gpdi.mdata.web.manage.database.utils;
import com.gpdi.mdata.web.manage.database.data.DBQueryData; import java.sql.Connection;
import java.sql.DriverManager; public class ConnectionManager {
private static Connection conn=null;
public ConnectionManager(){};
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) { e.printStackTrace();
}
}
public static Connection getConnection(DBQueryData dbQueryData){
try {
if(conn==null||conn.isClosed()) {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://"+dbQueryData.getUrl()+"/"+dbQueryData.getDbName();
String user = dbQueryData.getUser();
String password = dbQueryData.getPasswd(); Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
System.out.println("数据库链接成功");
} } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("数据库链接失败");
} return conn; }
public static void main(String[] args) { } }


  • 进行数据库查询,得到结果以对象方式存诸以便方便调用

package com.gpdi.mdata.web.manage.database.utils;
import com.gpdi.mdata.web.manage.database.data.DBList;
import com.gpdi.mdata.web.manage.database.data.DBQueryData;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import java.sql.*;
import java.util.*; //jdbc链接数据库,获取表名,字段名和数据
public class DBhepler {
private Connection conn=null;
private PreparedStatement ps=null;
public DBList search(DBQueryData dbQueryData) throws Exception {
DBList dbList=new DBList();
String sql=""; conn = ConnectionManager.getConnection(dbQueryData);
if(dbQueryData.getWhere()==null||dbQueryData.getWhere().equals("")){
sql="select * from "+dbQueryData.getTableName();
}
else {
sql="select * from "+dbQueryData.getTableName()+" where="+dbQueryData.getWhere();
}
// 获取所有表名 //Statement statement = conn.createStatement();
PreparedStatement pst =conn.prepareStatement(sql);
ResultSet resultSet=pst.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
//定义一个list去接受字段名
List<String> list=new ArrayList<>();
for (int i = 0; i < metaData.getColumnCount(); i++) {
// resultSet数据下标从1开始
String columnName = metaData.getColumnName(i + 1);
int type = metaData.getColumnType(i + 1);
if (Types.INTEGER == type) {
// int
} else if (Types.VARCHAR == type) {
// String
}
list.add(columnName);
System.out.print(columnName + "\t");
}
dbList.setRowTitle(list); List<List<String>> valueList=new ArrayList<>();
int j=0; System.out.println();
// 获取数据
while (resultSet.next()) {
List<String> colList=new ArrayList<>();
for (int i = 0; i < metaData.getColumnCount(); i++) {
// resultSet数据下标从1开始
//System.out.print(resultSet.getString(i + 1) + "\t");
colList.add(resultSet.getString(i + 1)); }
valueList.add(colList); j++;
}
dbList.setColCount(metaData.getColumnCount());
dbList.setRowCount(j);
dbList.setValueList(valueList); pst.close();
conn.close();
//pst.close();
// conn.close();
return dbList;
}
@RequestMapping
public Map<String, List<String>> SQLInsert(String [] zdName,List<List<Object>> list,DBQueryData dbQueryData){ Map<String, List<String>> resultMap=new HashMap<>();
List<String>countList=new ArrayList<>();
List<String> suList=new ArrayList();
List<String> fiList=new ArrayList(); //sql
int filed=0;
int success=0;
for(int li=0;li<list.size()-1;li++){
//sql语句前部分
StringBuffer sql=new StringBuffer();
sql.append("insert into file_1 (");
for (int zd=0;zd<zdName.length-1;zd++){
//zdName[zd]=zdList.get(zd).toString();
sql.append(zdName[zd]+",");
} sql.append(zdName[zdName.length-1]+") ");
//sql后部分
List valueList=list.get(li);
StringBuffer sqlEnd=new StringBuffer();
sqlEnd.append(" values(");
for (int v=0;v<valueList.size()-1;v++){
sqlEnd.append("'"+valueList.get(v)+"'"+",");
}
sqlEnd.append("'"+valueList.get(valueList.size()-1)+"'"+");");
sql.append(sqlEnd);
System.err.println("sql:"+sql);
conn= ConnectionManager.getConnection(dbQueryData);
try {
ps=conn.prepareStatement(sql.toString());
//ps.addBatch(insertSql);
ps.executeUpdate();
success++;
suList.add(sql.toString());
System.err.println("导入成功"+success);
} catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
filed++;
System.err.println("导入失败"+filed);
System.err.println("失败sql:"+sql);
fiList.add(sql.toString());
//return null;
}finally {
System.err.println("导入完成"); } } try {
conn.close();
System.err.println("关闭数据库成功");
} catch (SQLException e) {
System.err.println("关闭数据库失败"); }
countList.add(String.valueOf(success));
countList.add(String.valueOf(filed));
resultMap.put("count",countList);
resultMap.put("success",suList);
resultMap.put("filed",fiList);
return resultMap; } }


  • excel的导出

@RequestMapping
public static void exportToExcel(HttpServletRequest request,
HttpServletResponse response,DBQueryData dbQueryData) {
try {
System.err.println(dbQueryData);
String name =dbQueryData.getTableName();
DBhepler dBhepler=new DBhepler();
DBList dbList=dBhepler.search(dbQueryData);
Workbook workbook = createWorkbook(dbList, name); String attachmentName = name + ".xls"; String ua = request.getHeader("User-Agent");
boolean isChrome = (ua != null && ua.contains("Chrome")); try {
if (isChrome) {
attachmentName = java.net.URLEncoder.encode(attachmentName, "UTF-8");
}
else {
attachmentName = new String(attachmentName.getBytes("GB2312"), "iso8859-1");
}
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
} response.setHeader("Content-disposition", "attachment; filename=" + attachmentName);
response.setContentType("application/msexcel");
ServletOutputStream os = response.getOutputStream();
workbook.write(os);
os.close();
}
catch (Exception e) {
throw new RuntimeException(e);
}
} private static Workbook createWorkbook(DBList dbList, String name) throws Exception {
String sheetName = name;
Workbook workbook = new HSSFWorkbook();
Sheet sheet = null;
int a = dbList.getRowCount();
if (a > 65535) {
int length = a / 65535;
for (int i = 0; i <= length; i++) {
if (sheet != null) {
sheet = null;
}
sheet = workbook.createSheet(sheetName + i);
int colCount = dbList.getColCount();
Row titleRow = sheet.createRow(0);
List<String> RowList=dbList.getRowTitle();
for(int j=0;j<RowList.size();j++){
Cell cell = titleRow.createCell(j);
cell.setCellValue(RowList.get(j));
}
if ((i + 1) * 65535 < a) {
//for (int r = i * 65535; r < (i + 1) * 65535; r++) {
List<List<String>> valueList= dbList.getValueList();
for(int v=0;v<valueList.size();v++){
Row row = sheet.createRow(v+ 1);
List<String> lists=valueList.get(v);
for (int l=0;l<lists.size();l++){
Cell cell=row.createCell(l);
cell.setCellValue(lists.get(l));
} } //}
}
else {
//for (int r = i * 65535; r < a; r++) {
List<List<String>> valueList= dbList.getValueList();
for(int v=0;v<valueList.size();v++){
Row row = sheet.createRow(v+ 1);
List<String> lists=valueList.get(v);
for (int l=0;l<lists.size();l++){
Cell cell=row.createCell(l);
cell.setCellValue(lists.get(l));
}
}
// }
}
}
}
else {
sheet = workbook.createSheet(name);
Row titleRow = sheet.createRow(0);
List<String> RowList=dbList.getRowTitle();
for(int j=0;j<RowList.size();j++){
Cell cell = titleRow.createCell(j);
cell.setCellValue(RowList.get(j));
}
List<List<String>> valueList= dbList.getValueList();
for(int v=0;v<valueList.size();v++) {
Row row = sheet.createRow(v + 1);
List<String> lists = valueList.get(v);
for (int l = 0; l < lists.size(); l++) {
Cell cell = row.createCell(l);
cell.setCellValue(lists.get(l));
}
}
}
return workbook;
}


  • excel的导入

package com.gpdi.mdata.web.manage.database.utils;

import com.gpdi.mdata.web.manage.database.data.DBQueryData;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*; public class ReadExcel { public static void readExcel(InputStream file,String fileName,DBQueryData dbQueryData)throws IOException { String extension = fileName.lastIndexOf(".") == -1 ? "" : fileName
.substring(fileName.lastIndexOf(".") + 1);
if ("xls".equals(extension)) {
read2003Excel(file,dbQueryData);
} else if ("xlsx".equals(extension)) {
read2007Excel(file);
} else {
//throw new IOException("不支持的文件类型");
read2003Excel(file,dbQueryData);
}
} public static Map<String, List<String>> read2003Excel(InputStream file,DBQueryData dbQueryData)
{
DBhepler dBhepler=new DBhepler();
Map<String, List<String>> resultMap =new HashMap<>();
List<List<Object>> list = new ArrayList<>();
long Start;
try (HSSFWorkbook hwb = new HSSFWorkbook(file)) { System.err.println("sheet:" + hwb.getNumberOfSheets());
Start = System.currentTimeMillis();
HSSFSheet sheet = hwb.getSheetAt(0); Object value = null;
HSSFRow row = null;
HSSFCell cell = null;
int counter = 0;
System.err.println("s"+sheet.getLastRowNum());
//首行的内容,相当字段名
Object firstValue=getFirstRow(sheet);
String []ss=firstValue.toString().split(",");
for (int l=0;l<ss.length;l++){
System.err.println("ss:"+ss[l]);
}
//每行的每个单元格内容
for (int i = 1; i <=sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
if (row == null) {
continue;
} else {
counter++;
}
List<Object> linked = new ArrayList<>(); for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
cell = row.getCell(j);
Long ns=System.currentTimeMillis();
if (cell == null) {
continue;
}
Long ne=System.currentTimeMillis();
DecimalFormat df = new DecimalFormat("0");// 格式化 number String
// 字符
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
Long Ss=System.currentTimeMillis(); value = cell.getStringCellValue();
Long Se=System.currentTimeMillis();
//System.out.println( "Strting开始:"+Ss+"结束:"+Se);
break;
case XSSFCell.CELL_TYPE_NUMERIC:
Long nns=System.currentTimeMillis();
System.out.println(i + "行" + j
+ " 列 is Number type ; DateFormt:"
+ cell.getCellStyle().getDataFormatString());
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else if ("General".equals(cell.getCellStyle()
.getDataFormatString())) {
value = nf.format(cell.getNumericCellValue());
} else {
value = sdf.format(HSSFDateUtil.getJavaDate(cell
.getNumericCellValue()));
}
Long nne=System.currentTimeMillis();
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
System.out.println(i + "行" + j + " 列 is Boolean type");
value = cell.getBooleanCellValue();
break;
case XSSFCell.CELL_TYPE_BLANK:
System.out.println(i + "行" + j + " 列 is Blank type");
value = "";
break;
default:
System.out.println(i + "行" + j + " 列 is default type");
value = cell.toString();
}
if (value == null || "".equals(value)) {
continue;
}
linked.add(value);
} list.add(linked);
System.err.println(i); }
long end=System.currentTimeMillis(); System.err.println("总的开始:" + Start + "结束:" + end); resultMap= dBhepler.SQLInsert(ss, list, dbQueryData);}
catch (Exception e){ }
return resultMap;
} private static List<List<Object>> read2007Excel(InputStream file)
throws IOException {
List<List<Object>> list = new LinkedList<List<Object>>();
// 构造 XSSFWorkbook 对象,strPath 传入文件路径
XSSFWorkbook xwb = new XSSFWorkbook(file);
// 读取第一章表格内容
XSSFSheet sheet = xwb.getSheetAt(0);
Object value = null;
XSSFRow row = null;
XSSFCell cell = null;
int counter = 0;
for (int i = sheet.getFirstRowNum(); counter < sheet
.getPhysicalNumberOfRows(); i++) {
row = sheet.getRow(i);
if (row == null) {
continue;
} else {
counter++;
}
List<Object> linked = new LinkedList<Object>();
for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
cell = row.getCell(j);
if (cell == null) {
continue;
}
DecimalFormat df = new DecimalFormat("0");// 格式化 number String
// 字符
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
//System.out.println(i + "行" + j + " 列 is String type");
value = cell.getStringCellValue();
break;
case XSSFCell.CELL_TYPE_NUMERIC:
System.out.println(i + "行" + j
+ " 列 is Number type ; DateFormt:"
+ cell.getCellStyle().getDataFormatString());
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else if ("General".equals(cell.getCellStyle()
.getDataFormatString())) {
value = nf.format(cell.getNumericCellValue());
} else {
value = sdf.format(HSSFDateUtil.getJavaDate(cell
.getNumericCellValue()));
}
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
System.out.println(i + "行" + j + " 列 is Boolean type");
value = cell.getBooleanCellValue();
break;
case XSSFCell.CELL_TYPE_BLANK:
System.out.println(i + "行" + j + " 列 is Blank type");
value = "";
break;
default:
System.out.println(i + "行" + j + " 列 is default type");
value = cell.toString();
}
if (value == null || "".equals(value)) {
continue;
}
linked.add(value);
}
list.add(linked);
}
return list;
} public static void main(String[] args) { } private static Object getFirstRow(HSSFSheet sheet){ Object value = "";
HSSFRow row = null;
HSSFCell cell = null;
row = sheet.getRow(0);
for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) {
cell = row.getCell(j);
if (cell == null) {
continue;
}
DecimalFormat df = new DecimalFormat("0");// 格式化 number String
// 字符
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");// 格式化日期字符串
DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
//System.out.println(0 + "行" + j + " 列 is String type");
value = value+cell.getStringCellValue()+",";
break;
case XSSFCell.CELL_TYPE_NUMERIC:
System.out.println(0+ "行" + j
+ " 列 is Number type ; DateFormt:"
+ cell.getCellStyle().getDataFormatString());
if ("@".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue())+",";
} else if ("General".equals(cell.getCellStyle()
.getDataFormatString())) {
value = value+nf.format(cell.getNumericCellValue())+",";
} else {
value =value+ sdf.format(HSSFDateUtil.getJavaDate(cell
.getNumericCellValue()))+",";
}
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
System.out.println(0 + "行" + j + " 列 is Boolean type");
value = cell.getBooleanCellValue()+",";
break;
case XSSFCell.CELL_TYPE_BLANK:
System.out.println(0 + "行" + j + " 列 is Blank type");
value =value+ ""+",";
break;
default:
System.out.println(0 + "行" + j + " 列 is default type");
value = value+cell.toString()+",";
}
if (value == null || "".equals(value)) {
continue;
} }
//System.err.println("value:"+value);
return value;
}
}


  • 调用csv

@RequestMapping
public Map<String, List<String>> upload(HttpServletRequest request,DBQueryData dbQueryData) throws IOException {
System.err.println("进来了。。。。");
Map<String, List<String>> resultMap=new HashMap<>();
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 得到上传的文件
MultipartFile mFile = multipartRequest.getFile("file");
// 得到上传服务器的路径
String path = request.getSession().getServletContext()
.getRealPath("/WEB-INF/upload/");
File file = new File(path);
//判断上传文件的保存目录是否存在
if (!file.exists() && !file.isDirectory()) {
System.out.println(path+"目录不存在,需要创建");
//创建目录
file.mkdir();
}
// 得到上传的文件的文件名
String filename = mFile.getOriginalFilename();
InputStream inputStream = mFile.getInputStream();
String extension = filename.lastIndexOf(".") == -1 ? "" : filename
.substring(filename.lastIndexOf(".") + 1);
if ("xls".equals(extension)) {
//ReadExcel readExcel=new ReadExcel();
resultMap= ReadExcel.read2003Excel(inputStream, dbQueryData);
//inputStream.close(); //return resultMap;
// ReadExcel.readExcel(inputStream, filename, dbQueryData);
} else if ("csv".equals(extension)) {
resultMap=CSVUtils.importCsv(inputStream,dbQueryData);
} else {
//throw new IOException("不支持的文件类型");
//read2003Excel(file,dbQueryData);
// return resultMap;
} // 文件流写到服务器端
// FileOutputStream outputStream = new FileOutputStream(path);
//outputStream.write(b, 0, length);
//inputStream.close();
//outputStream.close();
inputStream.close();
return resultMap;
}

  • csv的导入导出

package com.gpdi.mdata.web.manage.database.utils;

import com.gpdi.mdata.web.manage.database.data.DBList;
import com.gpdi.mdata.web.manage.database.data.DBQueryData; import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*; public class CSVUtils { public static String TAB = "\r\n";
static{
Properties prop = System.getProperties();
String os = prop.getProperty("os.name").toLowerCase();
if(os.startsWith("win")){
TAB = "\r\n";
}else if(os.startsWith("linux") || os.startsWith("unix")){
TAB = "\n";
}else if(os.startsWith("mac")){
TAB = "\r";
}
} public static void exportCsv(HttpServletResponse response,DBQueryData dbQueryData) throwsException {
String fileName=dbQueryData.getTableName()+".csv";
DBhepler dBhepler=new DBhepler();
DBList dbList=dBhepler.search(dbQueryData);
List<String> titles=dbList.getRowTitle();
List<List<String>> data=dbList.getValueList();
StringBuffer sb = new StringBuffer();
OutputStream outputStream = null;
for (int i = 0; i < titles.size(); i++) {
if(i != titles.size() - 1){
sb.append(titles.get(i)).append(",");
}else{
sb.append(titles.get(i)).append(TAB);
}
} for (int i = 0; i < data.size(); i++) {
List<String> row = data.get(i);
for(int j = 0 ; j < row.size(); j++ ){
if(j != row.size() - 1){
sb.append(row.get(j)).append(",");
}else{
sb.append(row.get(j)).append(TAB);
}
} } try { response.addHeader("Content-Disposition","attachment;fileName=" + newString(fileName.getBytes("UTF-8"),"iso8859-1")); 
//response.addHeader("Content-Length", "" + sb.length()); 
//response.setContentType("application/csv;charset=UTF-8"); 
response.setContentType("multipart/form-data");//设置文件ContentType类型,这样设置,会自动判断下载文件类型
outputStream = response.getOutputStream(); outputStream.write(new byte []{( byte ) 0xEF ,( byte ) 0xBB ,( byte ) 0xBF });//加上bom头,才不会中文乱码 
outputStream.write(sb.toString().getBytes("UTF-8"));
outputStream.flush();
} catch (IOException e) { }finally{
try {
outputStream.close();
} catch (IOException e) { }
}
} public static List<String> importCsv(File file){
List<String> data = new ArrayList<String>();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(file));
String line = "";
while((line = br.readLine()) != null){
data.add(line);
}
} catch (Exception e) { }finally{
try {
br.close();
} catch (IOException e) { }
} return data;
} public static Map<String, List<String>> importCsv(InputStream inputStream,DBQueryData dbQueryData){
List<String> data = new ArrayList<String>();
Map<String, List<String>> resultMap=new HashMap<>();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(inputStream,"Utf-8"));
String line = "";
while((line = br.readLine()) != null){
data.add(line);
}  } catch (Exception e) { }finally{
try {
br.close();
inputStream.close();
} catch (IOException e) { } } List<List<Object>> result=new ArrayList<>();
DBhepler dBhepler=new DBhepler();
if(data.size()>0) {
for (int i = 0; i < data.size(); i++) {
List<Object> valueList = new ArrayList();
if (i != 0) {
String cont[] = data.get(i).replace(""", "").split(",");
for (int j = 0; j < cont.length; j++) {
valueList.add(cont[j]);
}
result.add(valueList);
}
System.err.println("csv:" + data.get(i).replace(""",""));
}
String zdName[] = data.get(0).replace(""", "").split(",");
resultMap=dBhepler.SQLInsert(zdName, result, dbQueryData); }
else {
return resultMap;
}
return resultMap;
} }

 

java 调用jdbc 实现excel和csv的导入和导出的更多相关文章

  1. php中excel以及cvs等导入以及导出

    一般网站后台都有人员导入或者是订单导出之类的操作,今天分享一下几种php excel cvs等文件导入导出的办法. 第一种比较简单的,自己写的,不引用任何excel类.但是会有bug,代码如下: 首先 ...

  2. 在Asp.Net MVC中使用NPOI插件实现对Excel的操作(导入,导出,合并单元格,设置样式,输入公式)

    前言 NPOI 是 POI 项目的.NET版本,它不使用 Office COM 组件,不需要安装 Microsoft Office,目前支持 Office 2003 和 2007 版本. 1.整个Ex ...

  3. java调用POI读取Excel

    HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls:XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx: 1.注意点 getPhy ...

  4. 用JDBC把Excel中的数据导入到Mysql数据库中

    步骤:0.在Mysql数据库中先建好table 1.从Excel表格读数据 2.用JDBC连接Mysql数据库 3.把读出的数据导入到Mysql数据库的相应表中 其中,步骤0的table我是先在Mys ...

  5. Java web实时进度条整个系统共用(如java上传、下载进度条、导入、导出excel进度条等)

    先上图: 文件上传的: 2017-05-04再次改进.在上传过程中用户可以按 Esc 来取消上传(取消当前上传,或者是全部上传)... 2019-03-26更新进度条显示体验 从服务器上压缩下载: 从 ...

  6. mysql的csv数据导入与导出

    # 需要station_realtime存在 load data infile 'd:/xxxx/station_realtime2013_01.csv' into table `station_re ...

  7. java使用POI操作excel文件,实现批量导出,和导入

    一.POI的定义 JAVA中操作Excel的有两种比较主流的工具包: JXL 和 POI .jxl 只能操作Excel 95, 97, 2000也即以.xls为后缀的excel.而poi可以操作Exc ...

  8. js原生导出excel和csv

    ​ 严格意义来说并不是真正的excel文件,只是可以用excel打开查看而已,实际上的格式是逗号分隔文件即csv文件. 这里有几个坑要说一下: 不加Unicode的utf8头部标识excel打开文件会 ...

  9. Java导出Excel和CSV(简单Demo)

    Java导出Excel和CSV的简单实现,分别使用POI和JavaCSV. JavaBean public class ReportInfo { int id; String date; int nu ...

随机推荐

  1. oj 小黑华丽的逆袭机会

    Problem H: 小黑华丽的逆袭机会 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 79  Solved: 7 [Submit][Status][ ...

  2. iOS 混合网页开发 问题

    在利用JavaScriptCore与H5交互时出现异常提示: This application is modifying the autolayout engine from a background ...

  3. [转]Java虚拟机类加载机制浅谈

    Java语言是一种编译后再经过解释器执行的过程, 解释器主要就是如何处理解释Class文件的二进制字节流.JVM主要包含三大核心部分:运行时数据区,类加载器和执行引擎. 虚拟机将描述类的数据从Clas ...

  4. oFixed() 方法

    oFixed() 方法可把 Number 四舍五入为指定小数位数的数字. 在本例中,我们将把数字舍入为仅有一位小数的数字: Show the number 13.37 with one decimal ...

  5. lightoj 1408 Batting Practice

    题意:一个人若连续进k1个球或连续不进k2个球,游戏结束,给出这个人进球的概率p,求到游戏结束时这个投球个数的期望. 进球概率为p,不进概率 q=1-p 设 f[i] 表示连续 i 次不进距离连续k2 ...

  6. Beyond Compare设置默认为ANSI格式

    工具 -> 文件格式 -> 选中C,C++,... -> 转换 -> 外部程序(ANSI文件名) 且 编码(选“ANSI”)-> 保存 -> 关闭

  7. Oracle数据库的启动和关闭

    深刻理解Oracle数据库的启动和关闭 Oracle数据库提供了几种不同的数据库启动和关闭方式,本文将详细介绍这些启动和关闭方式之间的区别以及它们各自不同的功能. 一.启动和关闭Oracle数据库 对 ...

  8. SingleNumber python实现

    Single Number Given an array of integers, every element appears twice except for one. Find that sing ...

  9. MYSQL 引擎的情况

    方法 1: show engine innodb status; ------------------------------------------------------------------- ...

  10. 8. java.lang.ArithmeticException

    java.lang.ArithmeticException 数学运算异常 当算术运算中出现了除以零这样的运算就会出这样的异常.