Main   Products   Offshore Outsourcing   Customers   Partners   ContactUs  
JDBC Databases
  HXTT Access v7.0
  HXTT Cobol v4.0
  HXTT DBF v7.0
  HXTT Excel v6.0
 
  Buy Now
  Support
  Download
  Document
  FAQ
  HXTT Paradox v7.0
  HXTT PDF v1.1
  HXTT Text(CSV) v7.0
  HXTT Word v1.0
  HXTT XML v3.0
Offshore Outsourcing
Free Resources
  Firewall Tunneling
  Search Indexing Robot
  Conditional Compilation
  Password Recovery for MS Access
  Password Recovery for Corel Paradox
  Checksum Tool for MD5
  Character Set Converter
  Pyramid - Poker of ZYH
   
   
   
Heng Xing Tian Tai Lab of Xi'an City (abbr, HXTT)

HXTT Excel
Cannot read excel (.xlsx) file
Srikanth
2012-07-11 13:30:19.0
Hi,
I using InputStream to create in memory DB, The file is being uploaded from client side, so i am able to get the InputStream from request.getInputStream. But, while creating DB, i am getting the following error
java.sql.SQLException: An invalid (or older version) Excel XLS file
at com.hxtt.global.SQLState.SQLException(Unknown Source)

Please help.

PS: I can able to successfully create DB by using FileInputStream and hardcoding the path of excel file inside java. But, getting error when file comes from clientside
Re:Cannot read excel (.xlsx) file
HXTT Support
2012-07-11 15:53:55.0
>But, getting error when file comes from clientside
If those files can be opened by HXTT Excel locally, then your code should contain errors. You can email us your sample, then we will check it.
Re:Re:Cannot read excel (.xlsx) file
Srikanth
2012-07-12 04:20:02.0
Sure, i will email the code to support@hxtt.com
Re:Re:Re:Cannot read excel (.xlsx) file
Srikanth
2012-07-12 06:32:20.0
I am using JDK 1.3, Excel_JDBC20.jar and WAS 5.0

Here is the code

JSP:


Login Page








FileUploadServlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
InputStream in = request.getInputStream();

try {
Class.forName("com.hxtt.sql.excel.ExcelDriver").newInstance();
String url="jdbc:excel:///_memory_/";//Enabled it if you have not disk access right.
Properties properties=new Properties();
properties.setProperty("tmpdir","_memory_");//Enabled it if you have not disk access right.
properties.setProperty("delayedClose","-1");//Release database at once.
properties.setProperty("versionNumber","XLSX");
Connection con = DriverManager.getConnection(url,properties);
PreparedStatement pstmt;
String sql = "create database if not exists test ?";
pstmt = con.prepareStatement(sql);
pstmt.setObject(1,in);
pstmt.executeUpdate();
pstmt.close();
in.close();
sql = "Select * from test.Sheet1";
//sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES ";
Statement stmt=con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
ResultSetMetaData resultSetMetaData = rs.getMetaData();
int iNumCols = resultSetMetaData.getColumnCount();
for (int j = 1; j <= iNumCols; j++) {
System.out.println(resultSetMetaData.getColumnLabel(j)
+ " " + resultSetMetaData.getColumnTypeName(j)
+ " " + resultSetMetaData.getColumnDisplaySize(j)
);
}
Object colval;
rs.beforeFirst();
long ncount = 0;
while (rs.next()) {
ncount++;
for (int j = 1; j <= iNumCols; j++) {
colval = rs.getObject(j);
System.out.print(colval + " ");
}
System.out.println();
}
System.out.println("row count:"+ncount);
rs.close();
stmt.execute("drop database test");
stmt.close();
con.close();
}
catch( SQLException sqle )
{
do
{
System.out.println(sqle.getMessage());
System.out.println("Error Code:"+sqle.getErrorCode());
System.out.println("SQL State:"+sqle.getSQLState());
sqle.printStackTrace();
}while((sqle=sqle.getNextException())!=null);
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

}
Re:Re:Re:Re:Cannot read excel (.xlsx) file
HXTT Support
2012-07-12 17:28:14.0
It's an issue about how to parse multipart/form-data .

Solutions:

Solution A:

1. download http://www.servlets.com/cos/index.html
2. invoke getParameters() on com.oreilly.servlet.MultipartRequest
It's at http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html .

Solution B:

1. download http://jakarta.apache.org/commons/sandbox/fileupload/
2. invoke readHeaders() in
org.apache.commons.fileupload.MultipartStream
It's at http://commons.apache.org/fileupload/streaming.html . A sample is at http://www.javapractices.com/topic/TopicAction.do?Id=221 .

Solution C:

1. download http://users.boone.net/wbrameld/multipartformdata/
2. invoke getParameter on
com.bigfoot.bugar.servlet.http.MultipartFormData

Solution D:

Use Struts. Struts 1.1 handles this automatically.
Re:Re:Re:Re:Re:Cannot read excel (.xlsx) file
Srikanth
2012-07-13 08:29:33.0
I have tried Solution E :) (part of Solution B)
Using Apache Fileupload (Its pretty simple and fits my requirement).
Sample : http://www.kodejava.org/browse/55.html

Thanks a lot for developing such a nice API. I tried 10 different API's/Solutions none fit my requirement as HXTT did.

Search Key   Search by Last 50 Questions




Google
 

Email: webmaster@hxtt.com
Copyright © 2003-2019 Heng Xing Tian Tai Lab of Xi'an City. | All Rights Reserved. | Privacy | Legal | Sitemap