Reading from an excel file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rich_Kanter
Posted On:   Tuesday, December 4, 2001 02:07 PM

I am new to Java and trying to read from an excel file using the JDBC:ODBC bridge. I have gotten to the point where I can read from the file, but I can not read the first row because it wants it to be headings (which it isn't). The following is the code I am currently trying to mocel after. public void runThisThing(File ExcelFile) throws Exception { Connection connection = null; ResultSet testResultSet = null; PreparedStatement ps = null; int count = 0; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connection = DriverManager.getConnection("jdbc:odbc:ExcelDSN","0",""); Statement testStatement = connection.createStatement();    More>>

I am new to Java and trying to read from an excel file using the JDBC:ODBC bridge. I have gotten to the point where I can read from the file, but I can not read the first row because it wants it to be headings (which it isn't). The following is the code I am currently trying to mocel after.
public void runThisThing(File ExcelFile) throws Exception
{
Connection connection = null;
ResultSet testResultSet = null;
PreparedStatement ps = null;

int count = 0;


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection("jdbc:odbc:ExcelDSN","0","");

Statement testStatement = connection.createStatement();

String testString = "SELECT * FROM [Sheet1$]";

testResultSet = testStatement.executeQuery(testString);

if (testResultSet != null);
{
while (testResultSet.next())
{
}
}



if (testResultSet != null)
{
testResultSet.close();
testResultSet = null;
}

}
Thank you in advance for your time and efforts.

   <<Less

Re: Reading from an excel file

Posted By:   Bernie_Acs  
Posted On:   Wednesday, December 5, 2001 10:13 AM

Recent Question indicates that the first row should be column headings as you noticed. The indication may be that you will have to fetch this first row by using the ResultSetMetadata Object which should be contain column names and types, you would know of course that this information is data and not identifiers. It would pay in the long run to have the format of Worksheets altered to indlcude column identifiers if this process your are creating is to be reused on a regular basis

You might consider reviewing the results returned by a search for the String "Excel ODBC" in this forum which will lead you to several recent discussions on this topic matter. Some also include code snipplets , examples, and other valuable insights.
About | Sitemap | Contact