Import data in the database into Excel in JSP

zhaozj2021-02-16  77

A project I have recently made is to combine the data in the database to Excel in the JSP page, I have made a bean that can be easily implemented.

Package com.javatnt.excel; / *** @ (#) CEXCEL.JAVA 1.0 04/03/16 * Title: * Description: * Copyright: Copyright (c) 2003 * Company: * @Author Donggen * @version 2.0 * /

Import java.io. *; import java.sql. *; import com.javatnt.excel. *; import jxl. *; import jxl.write. *; public class exchange {

// myexecsql connection database class myexecsql conn = null; // constructor public excel () {conn = new myexecsql ();} / * =================== ======================================================================================================================================================================= Number === Title: Field name === SQL: SQL string === path: file generation path === Return value: === Developer: Dong Zhengli === Development time: 2004-03-16 = == Modification Record: =============================================== ============== * /

Public void createexcel (String [] Title, String SQL, String Path) {

INT i = 0; int J = 0;

ResultSet RS = NULL;

Try {// Establish connection with the database Conn.myconnectsqlserver ("dzl", "traffic"); rs = conn.execQuery (SQL);

// Build a Workbook object, read-only Workbook object //: Create a writable Excel workbook WritableWorkbook wwb = workbook.createworkbook (new fileoutputstream (path)); Writablesheet WS = Wwb.createsheet ("Sheet1", 0); For (i = 0; i

I use Java's open source project JXL can be easily downloaded online.

转载请注明原文地址:https://www.9cbs.com/read-22241.html

New Post(0)