Reading to an array from excel


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Reading to an array from excel

  1. #1
    Join Date
    Sep 2003
    Posts
    2

    Question Reading to an array from excel

    I'm trying to read some data from an excel spread sheet into an array in java. But I get an error message when trying to compile the code; that the array from jdbc is not compatible with the java array.

    Here is the error message:
    Code:
    xlread4.java:32: incompatible types
    found : java.sql.Array
    required: int[]
    int array[] = rs.getArray(i);
    ^
    1 error
    Can anybody help me with this problem?

    The code I use is a the bottom:
    Code:
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    import java.util.*;
    
    public class xlread4{
    
      private static int array[] = new int[10];
    
      public static void main(String[] args){
        Connection connection = null;
    
    
        try{
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection con = DriverManager.getConnection( "jdbc:odbc:cordinates", "", "" );
          Statement st = con.createStatement();
          ResultSet rs = st.executeQuery( "select x1 from [lines$]" ); 
    
          ResultSetMetaData rsmd = rs.getMetaData();
          int numberOfColumns = rsmd.getColumnCount();
    
          while (rs.next()) {
            for (int i = 1; i <= numberOfColumns; i++) {
              if (i > 1) System.out.print(", ");
                int array[] = rs.getArray(i);
                System.out.print(array);
              }
              System.out.println("");
            }
    
            st.close();
            con.close();
          } 
          catch(Exception ex) {
            System.err.print("Exception: ");
            System.err.println(ex.getMessage());
          }
       }
    }
    ArchAngel: "Please use CODE tags to format your code."

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    getArray()

    The getArray() method does return an Array, not int[].

    Look at : http://java.sun.com/j2se/1.3/docs/ap...a.lang.String)

    Now I am not sure you want to get that Array. What do you expect to get? What's in the excel?

    Sharbov.

  3. #3
    Join Date
    Sep 2003
    Posts
    2
    There are only number in the excel file. For example A2 = 0, A3 = 55, A4 = 40 etc

    I want the java application to read them into an array. But since I can't read one cell at the time, I've got to read the entire column and then try and convert it into a java array

    Ace

  4. #4
    Join Date
    Mar 2003
    Posts
    834

    Unhappy

    This doesn't sound anything like Excel's file format! I think you're going to have to explain what you're trying to do and how you're trying to do it.

    From your code it looks as though you're querying a database?
    ArchAngel.
    O:-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center