Steps for running DB2 sample
If you are using an IBM plug-in and do not have the sun.jdbc.odbc package in your classpath, you can instead run this sample with IBM DB2.
- Create a DB2 database. Call the database "AMNU" and create a table "CUSTRECS" with columns "NAME", "ADDRESS", "PHONE", "DATE", "AMOUNT" and "COMMENT".
- Put appropriate DB2 drivers in your classpath. Rather than using sun.jdbc.odbc.JdbcOdbcDriver, we will now use COM.ibm.db2.jdbc.net.DB2Driver to connect to our local database. This and other needed classes are found in db2java.zip, which was likely placed in \SQLLIB\java when you installed DB2. There are different ways of getting these needed files in your classpath, depending on your setup.
- Edit the macro for your DB2 database.
- In the line:
change hostname to the name of your machine running DB2.<create name="$database$" type="DB" value="$new DB('jdbc:db2://hostname:6789/AMNU', 'COM.ibm.db2.jdbc.net.DB2Driver')$" />
- Find the following two perform actions:
and modify them with and ID and Password that will connect to your DB2 database.<perform value="$database.setUserID('db2admin')$" /> <perform value="$database.setPassword('db2admin')$" />
- In the line:
- Follow steps 3-7 above, this time importing AMNUDB2.mac.
Note some differences in the two macros:
- The syntax of the table name in the SQL query is different. For
Excel:
For DB2:[CUSTRECS$]
CUSTRECS
- As mentioned before, we are using a different driver to connect to the database.
- This time we needed to use EditDB's setUserID and setPassword methods to specify the appropriate ID and Password to connect to the database.
- This macro does not launch the local database when you are done making your additions. You can verify that the records were properly added by performing a "Select * from CUSTRECS" query on the database.