Example of reading data from Excel in DB2 database (1)

Source: Internet
Author: User

This document provides an example of how to read and import data from a DB2 database in Excel. The example has two functions: reading Excel from POI, and connecting to a DB2 database and executing SQL. For your reference, I hope to enlighten you.

Have you ever encountered the need to read data from Excel? Import data to the database and save it. Finally, you can use the report to read the database and display it, which is relatively simple. I checked the information about the two, and it didn't matter. The required functions are relatively simple. As long as I can read the Excel Data, I decided to use POI and trust apache. It was really easy to use, I found a source code on the Internet, and copied it and changed it slightly to use it.

The following code is a Demo with two functions: POI reading Excel, and DB2 database connection and SQL Execution.
Import Java. io. FileInputStream; import
Java. io. IOException; import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. SQLException;
Import java. SQL. Statement;
Import org. apache. poi. hssf. usermodel. HSSFCell;
Import org. apache. poi. hssf. usermodel. HSSFRow;
Import org. apache. poi. hssf. usermodel. HSSFSheet;
Import org. apache. poi. hssf. usermodel. HSSFWorkbook;
Import org. apache. poi. poifs. filesystem. POIFSFileSystem;
Public class POITest {private static Connection conn = null;
Private static Statement stmt = null;
Private static boolean connectDB2 ()
{String url = "";
String username = "username ";
String password = "password ";
// Load the driver to connect to the database try
{// Add the class library driver package db2jcc. jar and db2jcc_license_cu.jarClass.forName
("Com. ibm. db2.jcc. DB2Driver ");
Url = "JDBC: db2: // 192.168.0.1: 50000/dbname ";


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.