日期:2014-05-17  浏览次数:20784 次

请问上传EXCEL文件这个怎么传给类

是一个通过WEB上传EXCEL然后插入到数据库的

类的代码里,文件是这样得来的,
InputStream fs = new FileInputStream("data/user.xls");

JAVA完整代码:
package com.mypack;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class TestExcel {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO 自动生成方法存根
                Cell cell = null;
                String sql = null;
                String insertDate = "";
                try {

                        // 加载postgresql驱动
                        Class.forName("org.postgresql.Driver");
                        Connection con = DriverManager.getConnection(
                                        "jdbc:postgresql://localhost:5432/mydb", "postgres",
                                        "postgres");
                        // 使用事务。不用也无所谓
                        con.setAutoCommit(false);
                        Statement smt = con.createStatement();
                        // if (smt != null) System.out.println("smt is ok!");
                        // 加载excel文件
    &n