Table of Contents
1. 实现目标
3. 设计kettle的转换文件
3.1. 设计步骤
3.2. 配置步骤
3.3. 配置参数
4. 在java调用转换
Home Database Mysql Tutorial 利用kettle组件导入excel文件到数据库

利用kettle组件导入excel文件到数据库

Jun 07, 2016 pm 04:10 PM
excel use import database document components

利用kettle组件导入excel文件到数据库 1. 实现目标 把excel文件内容导入到目标表中;然后用java调用kettle的转换。excel文件的内容只有两列,示例如下: 数据库表的结构如下: vcD4KCjxoMz4yLiAgICAgyei8xrfWzvY8L2gzPgoKPHVsPgo8bGk+CjxwPgrKudPDb3JhY2xluq/

利用kettle组件导入excel文件到数据库

1. 实现目标

把excel文件内容导入到目标表中;然后用java调用kettle的转换。excel文件的内容只有两列,示例如下:

\

数据库表的结构如下:

\

喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KCjxoMz4yLiAgICAgyei8xrfWzvY8L2gzPgoKPHVsPgo8bGk+CjxwPgrKudPDb3JhY2xluq/K/b3ivvbJz828u8bJq9DQtcTX1rbOo7rBvbj2dXVpZLrNwb249s+1zbPI1cbao7s8L3A+CgoKPHA+0OjSqsn6s8l1dWlko6zV4rj21NpvcmFjbGXW0L/J0tTA+9PDU1lTX1VVSUQoKbqvyv3Ktc/Wo7s8L3A+Cgo8cCBhbGlnbj0="left">需要生成当前时间作为创建时间和修改时间,使用oracle的to_char(sysdate,’yyyy-MM-dd hh:mm:ss’)实现;

  • 使用命名参数解决蓝色行字段

    创建人及修改人的ID(两者一致)、组织ID、来源文件的ID;分别使用命名参数:

    ${USER_ID}、${ORG_ID}、${FILE_ID}、${FILE_NAME};

    其中文件名称是读取excel步骤要使用的;

    • 使用excel行内容作为绿色行的值

      即企业名称和组织机构代码两个字段;

      • 使用默认值作为白色行的值

        3. 设计kettle的转换文件

        使用excel输入步骤读取excel内容,使用执行sql脚步步骤把记录插入数据表中;

        3.1. 设计步骤

        从输入类别中拖动excel input步骤到工作区,从脚步类别中拖动执行sql 脚步到工作区;按shift键,从excel input步骤连接到sql脚步步骤。如下图:

        \

        3.2. 配置步骤

        • 配置excel步骤

          双击excel步骤,打开配置对话框:

          \

          \

          \

          • 配置数据库连接

            记得把oracle的jdbc驱动加到kettle的lib目录中,可以测试连接。

            \

            • 配置执行sql脚步步骤

              双击该步骤打开配置,首先选择前面配置的数据库连接,然后写insert语句。需要注意的是字符类型要用引号括起来,即使是变量或?都需要括起来。

              问号的内容需要在parameters中配置对应的流字段;

              因为需要执行多行,需要选中Execute for each row 选项;

              因为有变量,需要选中Variable substutution选项;

              \

              3.3. 配置参数

              前面分析了需要四个参数,分别在两个步骤使用到了,所以需要给转换配置四个命名参数: USER_ID、ORG_ID、FILE_ID、FILE_NAME;

              双击工作区空白部分打开转换配置,输入相应的参数,也可以添加默认值,用于在kettle中进行测试使用,直到测试没有错误。

              \

              至此,在kettle的设计工作已经做完,大家可以参考这篇博客文章,关于动态查询的详细说明,地址:http://blog.csdn.net/neweastsun/article/details/39287809;

              4. 在java调用转换

              调用之前,需要准备上述四个参数的内容,然后把参数传给转换执行;详细内容参考这篇博客文章:

              http://blog.csdn.net/neweastsun/article/details/40886841

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Solve complex financial calculations with 3 Excel financial functions Solve complex financial calculations with 3 Excel financial functions Jul 21, 2024 pm 06:39 PM

Original title: "These 3 Excel financial functions are undervalued again!" 》Author of this article: Xiaohua Editor of this article: Zhu Lan Recently, Xiaohua encountered an interesting question, which came from the soul of an old friend: How to choose between monthly annuity and private mutual insurance finance? The basic information of these two financial products is as follows: Monthly annuity: monthly payment of 1,000 yuan, annualized interest rate of 3%, 2-year term, and one-time withdrawal of principal and interest upon maturity. Mutual insurance finance: Pay a principal of 1,000 yuan every month, and the monthly principal will be calculated at 10% interest, with a 2-year term. There are 24 people participating in the same product. Every month, one person must receive all the principal and interest paid by others. The next month after receiving the payment, one person must pay an interest of 100 yuan/month. How to compare the pros and cons of these two financial products? we can

See all articles