Suppose you love jigsaw puzzles and decided to open a store for selling them. You have made all the arrangements and the only missing thing is the software. You have already acquired a software to handle your business, but you still have one hard task to do—insert data into the database, that is, load the database with the basic information about the products you are about to sell.
As this is the first of several tutorials in which you will interact with that database, the first thing you have to do is to create the database.
For MySQL-specific tasks such as the creation of a database, we will use the MySQL Query Browser, included in the MySQL GUI Tools software. If you don't have it or don't like it, you can accomplish the same tasks by using the MySQL Command Line Client or any other GUI Tool.
js.sql
. localhost
as Server Host, and as Username and Password, enter the name and password of the user you created when you installed the software . js
, appears. js
tree and you will see the tables of the database.Now that the database has been created, let's load some data into it:
manufacturers.xls
file. localhost
as Host Name and js
(the database you just created) as Database Name, and as User Name and Password, enter the name and password of the user you created when you installed MySQL. For other settings in the window, leave the default values. Test the connection to see if it has been properly created. manufacturers.xls
file. js
as Connection, as Target table, browse and select the table manufacturers or type it. Check the Specify database fields option. db_err_desc
as Error descriptions fieldname, db_err_field
as Error fields fieldname, and db_err_cod
as Error codes fieldname. SELECT
statement for that table such as:SELECT * FROM manufacturers m;
In the first part of the tutorial, you created the Jigsaw Puzzle database.
In Spoon, you created a connection to the new database.
Finally, you created a transformation that read an Excel file with a list of puzzle manufacturers and inserted that data into the manufacturers table. Note that not all rows were inserted. The row that couldn't be inserted was reported in the log.
In the data for the tutorial, there was a description too long to be inserted in the table. That was properly reported in the log because you implemented error handling. Doing that, you avoided the abortion of the transformation due to errors like that. As you learned in the previous chapter, when a row causes an error, it is up to you to decide what to do with that row. In this case, the row was sent to the log and wasn't inserted. Other possible options for you are:
The Table output step is the main PDI step for inserting new data into a database table.
The use of this step is simple. You have to enter the name of the database connection and the name of the table where you want to insert data. The names for the connection and the table are mandatory, but as you can see, there are some extra settings for the Table output step.
The database field tab lets you specify the mapping between the dataset stream fields and the table fields.
In the tutorial the dataset had two fields—CODE
and NAME
. The table has two columns named man_code
and man_desc
.
As the names are different, you have to explicitly indicate that the CODE
field is to be written in the table field named man_code
, and that the NAME
field is to be written in the table field named man_desc
.
The following are some important tips and warnings about the use of the Table output step:
In the Table output step, you may have noted a button named SQL. This button generates the DDL to create the output table. In the tutorial, the output table, manufacturers
, already existed. But if you want to create the table from scratch, this button allows you to do it based on the database fields you provided in the step.
18.119.103.204