How to use Java to import excel data to a database

Source: Internet
Author: User
Recently I wrote some code about importing an excel file into a database. Of course, it can also be used as a supplement to the small project described above. I usually complete the function first, then encapsulate it into blocks, and then add it to the project. This is a record that has been successfully inserted into the data-driven database. The newly created table is db, which is under control

Recently I wrote some code about importing an excel file into a database. Of course, it can also be used as a supplement to the small project described above. I usually complete the function first, then encapsulate it into blocks, and then add it to the project. This is a record that has been successfully inserted into the data-driven database. The newly created table is db, which is under control

Recently I wrote some code about importing an excel file into a database. Of course, it can also be used as a supplement to the small project described above.

I usually complete the function first, then encapsulate it into blocks, and then add it to the project. My personal hobbies are not worth learning.

This is the data record that has been successfully inserted into the data-based database. The new table is db. This is the data input in the console. <喎?http: www.2cto.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + six + 7Suyse63Lbgz + six "brush: SQL;">/** import execl data to the database * @ author trsli **/public class CreateDBTable {private static Connection conn; private static String SQL = ""; private static StringBuffer buf = new StringBuffer (); static {conn = DBConnection. getConnection ();} public static void main (String [] args) {// data .xls file path System. out. println ("input file path:"); String filename = new partition (System. in ). nextLine (); // obtain the data content of the database to be inserted. Object [] [] contents = new PoiUtil (). getmessage (filename); // obtain the field name Object [] titles = new PoiUtil () of the table created by the database (). gettitles (filename); System. out. println ("input number table name:"); String fname = new partition (System. in ). nextLine (); try {String ziduan = ""; String blank = ""; PreparedStatement stmt = conn. prepareStatement (SQL); buf. append ("create table" + fname + "(id int primary key auto_increment"); // concatenate a string, it is mainly used to dynamically create data tables and insert data for (int I = 0; I

The entire code is very simple. You can extract the required methods from them for other purposes.

This is the display of data in the database. The original data is as follows:

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.