Results 1 to 3 of 3

Thread: Simple Question.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Simple Question.

    Hi.

    I'm new to java and I'm trying to run the following code.
    VB Code:
    1. import java.io.*;
    2. import java.sql.*;
    3.  
    4.  
    5.     public class ExcelReadTest{
    6.             public static void main(String[] args){
    7.                 Connection connection = null;
    8.  
    9.  
    10.                     try{
    11.                         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    12.                         Connection con = DriverManager.getConnection( "jdbc:odbc:exceltest" );
    13.                         Statement st = con.createStatement();
    14.                         ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
    15.  
    16.                         ResultSetMetaData rsmd = rs.getMetaData();
    17.                         int numberOfColumns = rsmd.getColumnCount();
    18.  
    19.  
    20.  
    21.  
    22.                             while (rs.next()) {
    23.  
    24.  
    25.                                     for (int i = 1; i <= numberOfColumns; i++) {
    26.                                         if (i > 1) System.out.print(", ");
    27.                                         String columnValue = rs.getString(i);
    28.                                         System.out.print(columnValue);
    29.                                     }
    30.                                     System.out.println("");
    31.                                 }
    32.  
    33.                                 st.close();
    34.                                 con.close();
    35.  
    36.  
    37.                                 } catch(Exception ex) {
    38.                                     System.err.print("Exception: ");
    39.                                     System.err.println(ex.getMessage());
    40.                                 }
    41.                             }
    42.                     }
    When I compile the code, I get this error message: JavaExcel.java:5: class ExcelReadTest is public, should be declared in a file named ExcelReadTest.java. How do I fix this?

    Thanks in advance.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    your .java file must be named ExcelReadTest.java (with the captialization, and everything)

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up Thanks crptcblade,

    I said it was a simple question!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width