如何写论文?写好论文?免费论文网提供各类免费论文写作素材!
当前位置:免费论文网 > 美文好词 > 优质好文 > 将excel导入数据库

将excel导入数据库

来源:免费论文网 | 时间:2017-06-01 05:43 | 移动端:将excel导入数据库

篇一:excel数据导入oracle中最简单的方法

excel数据导入oracle中最简单的方法:

如果你的单个excel文件不大的情况下(少于100000行):

1、在EXCEL中全选数据,然后COPY。接着打开PL/SQL DEVELOPER,打开SQL窗口,输入select * from mytable for update;然后执行,就可以看到查出目的表mytable数据,如果是空表,当然是没数据了。然后点击下面列表上方的锁(编辑数据), 再点一下加号(插入记录),下面列表多出一空白行,注意该行左边是有个黑色实心三角箭头的。

2、下面是最有技术难度也是最高明的一件事了:鼠标点击上面特意提到的黑色实心三角箭头,这时空白行被选中,全变成蓝色。然后右键,在弹出菜单中选择“粘贴”,over,等个几十秒,我电脑太慢了,一会数据就出来了,超级简单吧,没骗你吧?这里又让你见识到了PL/SQL DEVELOPER强大功能中的一个小功能了。。。。(后面几句纯属废话)

5、当然最后别忘了COMMIT。

真的完了。。。HOHO~~

说明:而且这个方法还有个好处就是对EXCEL中的日期型、数值型字段的处理也很正常,数据类型不会丢失。

方法一:

1、在本地创建一个Access数据库,将Excel数据先导入到Access。可直接导入点击鼠标右键,选择导入,文件类型选择要导入的Excel文件,也可通过创建宏用TransferSpreadsheet函数实现。

2、在本地创建ODBC,链接oracle数据库。将oracle中需要导入数据的表以链接表的方式在本地Access中创建(千万不要使用导入表)。

3、在Access数据库中创建插入查询将导入好的Excel数据导入到oracle中。

方法二:

先把Excel另存为.csv格式文件,如test.csv,再编写一个insert.ctl

用sqlldr进行导入!

insert.ctl内容如下:

load data --1、控制文件标识

infile \'test.csv\' --2、要输入的数据文件名为test.csv

append into table table_name --3、向表table_name中追加记录 fields terminated by \',\'--4、字段终止于\',\',是一个逗号

(field1,

field2,

field3,

...

fieldn)-----定义列对应顺序

注意括号中field排列顺序要与csv文件中相对应

然后就可以执行如下命令:

sqlldr user/password control=insert.ctl

方法三:

这里是借用delphi的database desktop来实现excel文件的导入

1、将excel表改为后缀为.dbf的dbase IV 表(最高版本)

.txt文本文件用excel打开

加上字段名

选数据

2、用delphi 自带的databbese desktop查看数据

3.tools->utilities->copy ->选择要导入的数据库

alias=none 选择.dbf文件

输入密码,转换(注意要大写)

4.成功导入后,按条件再加以修改

方法四:

打开excel文件,选另存为TXT文本文件,有了这个文本文件,就有很多方法可以导入到oracle中了,可以通过SQL Loader可以导入到Oracle 中,也可以通过pl/sql developer 导入,也可以通过Golden的imp/exp工具可以直接导入文本文件。。。。。等等,这些方法思路都一样,但是这种方法有一个缺点,就是文本文件会丢失数据类型信息。

方法五:

如果你的电脑同时也安装了sql server ,可以利用sql server 的导入导出数据工具DTS,数据源驱动选excel97-2000,然后选你的excel文件,目的驱动选Oracle in OraHome90,然后新建一个指向你的oracle 用户的系统类型的odbc数据源,注意输入大写的用户名和密码,然后按着向导下一步,后面几步自己可以自己看懂,就不详细介绍了,最后点完成,如果没有表,默认会首先创建表,然后COPY数据。注意EXCEL第一行要是字段名。

篇二:Excel导入,将数据导入到数据库

Java实现上传Excel文件,并读取

数据插入到数据库中

1、 第一步当然是搭环境了,新建一个Web项目,然后将需要

的jar包加入,在这里只列出导入Excel文件数据所需的jar包,其中包括:poi-3.0-rc4-20070503.jar、poi-contrib-3.0-rc4-20070503.jar

poi-scratchpad-3.0-rc4-20070503.jar,需要的包就这3个了 2、 然后就是写代码了,当然是先前台然后写后台代码 3、 前台页面代码:

<form name="f0" enctype="multipart/form-data" method="post" method=”upload/upload”>

<table>

<tr align="center">

<td>

<input id="file" name="file" type="File" style="width: 200px;"><input type="submit" id="upload" value="上传"

class="buttonC4"/></td>

</tr> </table> </form>

4、 后台代码:

//必须要说的是,导入Excel文件数据到数据库,Excel文件的格式必须都是文本格式的,如果不是文本格式的话,导入的时候读取文件时会出错,切记切记(ps:具体的可以不可以是其他的格式,这我就不是太清楚了,我反正试了,不行,如果有高手还可以有其他的办法,请给小弟分享一下,谢谢QQ:495537636)

public String Upload() throws Exception {

//这里需要强调一下,Excel文件有不止一个sheet页,所以这里根据你自己的具体情况而定,如果只有一个,只要是sheet0就行了,只要记住开始是从sheet0,然后往后排就行了,以下例子是3个sheet页try{ // // // // // // // ); // // // // // // //

FileOutputStream fos=new

FileInputStream fis=new FileInputStream(file); byte[] buffer=new byte[1024]; int len=0;

while((len=fis.read(buffer))>0){ }

fos.write(buffer,0,len);

FileOutputStream(realpath+"\\"+this.getFileFileName());

String path =

System.out.println(">>>>>path="+path); String path1 = request.getContextPath(); System.out.println(">>>>path1>>>>>"+path1); String realpath = path+"upload";

System.out.println(">>>>>realpath="+realpath); String propDir =

File file=this.getFile();

ServletActionContext.getServletContext().getRealPath("/");

PropertyUtil.getProperty("project.upload.dir"); //

System.out.println(">>>>>>="+realpath+"\\"+this.getFileFileName()

// // // // //{

this.context.put("message", "上传成功!"); Anv06 anv06 = null; Anv07 anv07 = null; Anv08 anv08 = null;

String readpath = realpath+"\\"+this.getFileFileName(); POIFSFileSystem ps = new POIFSFileSystem(new HSSFWorkbook workBook = new HSSFWorkbook(ps); HSSFRow row = null; int rowNum = 0; //这里是第一个sheet页

HSSFSheet sheet0 = workBook.getSheetAt(0);// 获得SHEET0(索引) for (rowNum = 2; rowNum <= sheet0.getLastRowNum(); rowNum++)

String ywhj1 = ""; String ywhj2 = ""; String ywhj3 = ""; String ywhj4 = "";

row = sheet0.getRow((short) rowNum); if (row != null) {

// 获取当前行的colNum位置的单元格

//这里是你的Excel文件中有多少列你就写多少了,也是从0开始的 HSSFCell cell0 = row.getCell((short) 0); HSSFCell cell1 = row.getCell((short) 1); HSSFCell cell2 = row.getCell((short) 2); HSSFCell cell3 = row.getCell((short) 3); HSSFCell cell4 = row.getCell((short) 4); HSSFCell cell5 = row.getCell((short) 5); HSSFCell cell6 = row.getCell((short) 6); HSSFCell cell7 = row.getCell((short) 7); HSSFCell cell8 = row.getCell((short) 8); HSSFCell cell9 = row.getCell((short) 9); HSSFCell cell10 = row.getCell((short) 10); HSSFCell cell11 = row.getCell((short) 11); HSSFCell cell12 = row.getCell((short) 12); HSSFCell cell13 = row.getCell((short) 13); HSSFCell cell14 = row.getCell((short) 14); HSSFCell cell15 = row.getCell((short) 15); HSSFCell cell16 = row.getCell((short) 16); HSSFCell cell17 = row.getCell((short) 17); HSSFCell cell18 = row.getCell((short) 18); HSSFCell cell19 = row.getCell((short) 19); HSSFCell cell20 = row.getCell((short) 20); HSSFCell cell21 = row.getCell((short) 21);

FileInputStream(file));

cell0).trim();

cell1).trim();

cell2).trim();

HSSFCell cell22 = row.getCell((short) 22); HSSFCell cell23 = row.getCell((short) 23); HSSFCell cell24 = row.getCell((short) 24); anv06 = new Anv06();

if (cell0 != null) {// 案件号CNV601 第1列

String str = swith(cell0.getCellType(), anv06.setCnv601(str);

}

if(cell1 != null){//案件题名CNV104 第2列

String str = swith(cell1.getCellType(), anv06.setCnv104(str);

}

if(cell2 != null){//案件类型CNV102 第3列

String str = swith(cell2.getCellType(), anv06.setCnv102(str);

}

if(cell3 != null){//业务环节1CNV103 第4列 ywhj1 = swith(cell3.getCellType(), cell3).trim(); anv06.setYwhj1(ywhj1); }else{

ywhj1 = ""; }

if(cell4 != null){//业务环节2 第5列 ywhj2 = swith(cell4.getCellType(), cell4).trim(); anv06.setYwhj2(ywhj2); }else{

ywhj2 = ""; }

if(cell5 != null){//业务环节3 第6列 ywhj3 = swith(cell5.getCellType(), cell5).trim(); anv06.setYwhj3(ywhj3); }else{

ywhj3 = ""; }

if(cell6 != null){//业务环节4 第7列 ywhj4 = swith(cell6.getCellType(), cell6).trim(); anv06.setYwhj4(ywhj4); }else{

ywhj3 = ""; }

if(cell7 != null){//业务代码类型CNV105

第8列

String str = swith(cell7.getCellType(), cell7).trim();

anv06.setCnv105(str);

}

if(cell8 != null){//业务代码 CNV106 String str = swith(cell8.getCellType(), cell8).trim();

anv06.setCnv106(str);

}

if(cell9 != null){//保管期限 CNV114 String str = swith(cell9.getCellType(), cell9).trim();

anv06.setCnv114(str);}

if(cell10 != null){//页数CNV107

String str = swith(cell10.getCellType(), cell10).trim();

anv06.setCnv107(str);

}

if(cell11 != null){//建档日期CNV110 String str = swith(cell11.getCellType(), cell11).trim();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");

Date date = formatter.parse(str); anv06.setCnv110(date);

}

if(cell12 != null){//建档人CNV109 String str = swith(cell12.getCellType(), cell12).trim();

anv06.setCnv109(str);

}

if(cell13 != null){//案卷号CNV602 String str = swith(cell13.getCellType(), cell13).trim();

anv06.setCnv602(str);}

if(cell14 != null){//备注CNV108 String str = swith(cell14.getCellType(), cell14).trim();

anv06.setCnv108(str);}

if(cell15 != null){//组织机构代码CNV122

第9列

第10列第11列

第12列第13列第14列第15列第16列

篇三:如何将Excel数据导入到postgresql数据库中

如何将Excel数据(*.xls)导入到ostgresSQL数据库中

一、Excel数据(*.xls)数据文件:

二、导入步骤:

1、根据Excel文件另存为".csv”格式文件; 2、根据Excel数据的属性创建表

-- Table: public.texipos -- DROP TABLE public.texipos; CREATE TABLE public.texipos (

number0 integer, simid character varying(20), lat numeric, lon numeric, speed integer, angle integer, time0 bigint, state text, rn integer, c_time character varying(100) ) WITH (OIDS=FALSE );

ALTER TABLE public.texiposOWNER TO postgres;

创建表如图下所示

3、打开psql.exe命令行工具

4、数据导入

在命令行中输入:copy 数据表名称 form '*.csv文件路径' with delimater ',';

回车;

数据导入的结果如下图所示:


将excel导入数据库》由:免费论文网互联网用户整理提供;
链接地址:http://www.csmayi.cn/meiwen/43161.html
转载请保留,谢谢!
相关文章