Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to read data from the excel file using java code.

807607Oct 12 2006 — edited Jan 15 2007
Hi to all,
I am using below code to getting the data from the excel file but I can't get the corresponding data from the specific file. can anyone give me the correct code to do that... I will waiting for your usefull reply......

advance thanks....

import java.io.*;
import java.sql.*;


    public class sample{


        	public static void main(String[] args){
        		Connection connection = null;


            		try{
            			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            			Connection con = DriverManager.getConnection( "jdbc:odbc:Mydsn","","" );
            			Statement st = con.createStatement();
            			ResultSet rs = st.executeQuery( "Select * from [Sheet1$]" );
            			System.out.println("sample:"+rs);
						ResultSetMetaData rsmd = rs.getMetaData();
						System.out.println("samplersd:"+rsmd);
            			int numberOfColumns = rsmd.getColumnCount();

						System.out.println("numberOfColumns:"+numberOfColumns);


                			while (rs.next()) {

								System.out.println("sample1:"+rs);
                    				for (int i = 1; i <= numberOfColumns; i++) {
                    					if (i > 1) System.out.print(", ");
                    					String columnValue = rs.getString(i);
                    					System.out.print(columnValue);
                    				}
                    				System.out.println("");
                    			}

                    			st.close();
                    			con.close();


                        		} catch(Exception ex) {
                        			System.err.print("Exception: ");
                        			System.err.println(ex.getMessage());
                        		}
                        	}
                    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2007
Added on Oct 12 2006
10 comments
3,956 views