Using Java to implement Excel data bulk Import Database

Source: Internet
Author: User
Tags access database import database

Whether it is to do software or Web site, I believe many people do in the time to use the database, and the database where the data from, can be manually added, but in most cases we are using the existing data, we want to use the development of tools to manage the existing data, if it is a small amount of data, manual input also no harm, But for a lot of data, manual input obviously has not been shown, and, more often, we want to add a batch of data on the software import, so no matter who is using this software, can easily manage the existing data, then our most commonly used data manager is what, no doubt Excel, But we do software is almost no one will use Excel as a db, so we have the problem is how to implement data in the software batch import, the data source is Excel, some people will say with ODBC Ah, can be imported anywhere, but this practice seems to have no technical content, And let the user do not have a batch import time to set up an ODBC data source is unrealistic, today Bo will introduce you to use the Spring Java implementation read Excel data files into the Access database (the principle of each database is the same), we use an open source API,JXL, the code is as follows:

public static Boolean Readexcel (String filePath) {
Boolean success=false;
Workbook RWB = null;
try{
InputStream is = new FileInputStream (FilePath);
RWB = Workbook.getworkbook (IS);
Get the first sheet table
Sheet rs = rwb.getsheet (0);
for (int k = 1; k < rs.getrows (); k++) {
String Major=rs.getcell (0, K). getcontents ();
String Year=rs.getcell (1, k). getcontents ();
String Class1=rs.getcell (2, k). getcontents ();
String Number1=rs.getcell (3, k). getcontents ();
String Name=rs.getcell (4, k). getcontents ();
String Sex=rs.getcell (5, k). getcontents ();
String People=rs.getcell (6, K). getcontents ();
String Area=rs.getcell (7, k). getcontents ();
String Birth=rs.getcell (8, k). getcontents ();
String Bodyid=rs.getcell (9, k). getcontents ();
String Phone=rs.getcell (ten, k). getcontents ();
String Hostel=rs.getcell (one, k). getcontents ();
String Father=rs.getcell (n, k). getcontents ();
String Mather=rs.getcell (all, K). getcontents ();
String Tel=rs.getcell (+, k). getcontents ();
String Studentstate=rs.getcell (n, k). getcontents ();
String Level1=rs.getcell (n, k). getcontents ();
String Party=rs.getcell (n, k). getcontents ();
String Duties=rs.getcell (k). getcontents ();
String English=rs.getcell (n, k). getcontents ();
String Computer=rs.getcell (j, K). getcontents ();
String Address=rs.getcell (+, k). getcontents ();
String Personstation=rs.getcell (n, k). getcontents ();
String Fundingstation=rs.getcell (23°c, K). getcontents ();
String Awardstation=rs.getcell (, K). getcontents ();
String Punishmentstation=rs.getcell (+ k). getcontents ();
String Other1=rs.getcell (+, k). getcontents ();
String picturepath= "";
if (Major.equals ("") | | Class1.equals ("") | | Name.equals ("") | | Number1.equals ("")) {
Success=false;
Break
}else{
String str1= "INSERT into information (Major,year,class1,number1,name,sex,people,area,birth,bodyid,phone,hostel, Father,mather,tel,studentstate,level1,party,duties,english,computer,address,personstation,fundingstation, Awardstation,punishmentstation,other1,picturepath) VALUES (' "+major+" ', ' "+year+" ', ' "+class1+" ', ' "+number1+" ', ' "+ Name+ "', '" +sex+ "', '" +people+ "', '" +area+ "', '" +birth+ "', '" +bodyid+ "', '" +phone+ "', '" +hostel+ "', '" +father+ "', '" + mather+ "', '" +tel+ "', '" +studentstate+ "', '" +level1+ "', '" +party+ "', '" +duties+ "', '" +english+ "', '" +computer+ "', '" + Address+ "', '" +personstation+ "', '" +fundingstation+ "', '" +awardstation+ "', '" +punishmentstation+ "', '" +other1+ "', '" +picturepath+ "')";
Commoncode.addinfo (STR1);
Commoncode.closeall ();
Success=true;
}
}
Rwb.close ();
}catch (Exception e) {
E.printstacktrace ();
}
return success;
}

Using Java to implement Excel data bulk Import Database

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.