Article View: borland.public.jbuilder.java.language
Article #193retreiving rows from ms xls
From: blink
Date: Wed, 24 May 2006 09:48
Date: Wed, 24 May 2006 09:48
83 lines
3044 bytes
3044 bytes
Hi,
I am trying to read the data in a MS Excel Sheet. I am able to create
the connection using jdbc-odbc bridge. But I am getting this exception
upon giving the query:
Exception: [Microsoft][ODBC Excel Driver] Too many fields defined
I am using the following code:
package com.ssc.pna.api.test;
import java.io.*;
import java.sql.*;
public class ExcelReadTest {
public static void main(String[] args)
{
Connection connection = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//The DSN created on my
system is MyExcellReader
Connection con = DriverManager.getConnection(
"jdbc:odbc:MyExcellReader" );
Statement st = con.createStatement();
System.out.println("Connection created");
//The excel sheet name
is Alert-Log
ResultSet rs = st.executeQuery( "Select * from [Alert-Log$]" );
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
System.out.println(numberOfColumns);
//To print the column headings
for (int i = 1; i <=rsmd.getColumnCount(); ++i)
{
if (i > 1){
System.out.print(", ");
}
String lValue = rsmd.getColumnName(i);
System.out.print(lValue);
}
System.out.println("");
st.close();
con.close();
} catch(Exception ex) {
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}
The value of rsmd.getColumnCount() is coming out to be 1 whereas my xls
has 8 columns. This might be a reason for exception
but even on replacing it with 8 in for loop, i m getting the same
exception.
Can anybody tell me the reason and solution for this problem
Thanks a lot,
Cheree
Technical Details
Message-ID:
<1148464091.492551.278680@u72g2000cwu.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!u72g2000cwu.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,52d971a06e099309,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!u72g2000cwu.googlegroups.com!not-for-mail From: "blink" <cheree.singal@wipro.com> Newsgroups: borland.public.jbuilder.java.language Subject: retreiving rows from ms xls Followup-To: borland.public.jbuilder.java.language Date: 24 May 2006 02:48:11 -0700 Organization: http://groups.google.com Lines: 84 Message-ID: <1148464091.492551.278680@u72g2000cwu.googlegroups.com> NNTP-Posting-Host: 203.91.193.6 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1148464096 28882 127.0.0.1 (24 May 2006 09:48:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 24 May 2006 09:48:16 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: u72g2000cwu.googlegroups.com; posting-host=203.91.193.6; posting-account=Oyhs6w0AAADXGLlwZj-h0AnXf143amQo