Java does not rely on reading Excel files

Source: Internet
Author: User

when it comes to Java reading Excel files, it's much more of a poi or jxls, but it's time to read a book today. Mentioned in the use of Jdbcodbcdriver this driver class in the case of not relying on third-party libraries can also complete the reading of the Excel file, the online search for a reason and then wrote a sample run through, in this record.

Java read database Everyone is very familiar with the need for a data source and corresponding driver. The developer is driven by the JDBC operation. Drive to operate the database again. Then Java reads the Excel file similarly. In Windows systems, the ability to register an Excel file as an ODBC data source is:
A. Control Panel > Administrative Tools > Data Sources (ODBC)

B. In the User DSN tab, click Join, select Driver do Microsoft Excel (*.xls)


c. Click Finish to fill in the data source name. Finally select the book, which is the Excel file address that you selected as the data source
The name of the data source is most important. It will act as part of the URL that gets the connection.

After a good data source is ready to write code, a scale such as the following:

public class Excelreader {private String ENTRY;//ODBC data source name public Excelreader (String entry) {this.entry = entry;} SheetName is the sheet name public String read (string sheetname) throws Exception {StringBuilder builder = new StringBuilder (); Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver"). newinstance (); Connection Connection = Drivermanager.getconnection ("JDBC:ODBC:" + entry); Statement Statement = Connection.createstatement (); ResultSet rs = statement.executequery ("SELECT * FROM [" + SheetName + "$]"), while (Rs.next ()) {Builder.append (rs.getobject (1)); /schematic Read only a list of}rs.close (); Statement.close (); Connection.close (); return builder.tostring ();} public static void Main (string[] args) throws Exception {Excelreader reader = new Excelreader ("ETL"); System.out.println (Reader.read ("Test"));}}

the principle is that the development is driven by the JDBC Operation Jdbcodbcdriver, the Jdbcodbcdriver Drive connects the ODBC data source. Then the ODBC operation connects to the Excel file (Windows complete). The purpose of reading the Excel file is completed by step-by-step adaptation.


Java does not rely on reading Excel files

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.