🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.language
1 messages
1 total messages Started by blink Wed, 24 May 2006 09:48
retreiving rows from ms xls
#193
Author: blink
Date: Wed, 24 May 2006 09:48
83 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads