dcsimg
read excel data
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   naresh_babu
Posted On:   Friday, March 23, 2001 09:49 AM

Hi,
I need to read data from excel using JDBC.
When i give:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection"Jdbc:Odbc:ExcelDSN","","");
Statement st = con.createStatement();

Exception:
I am getting Exception as:java.sql.SQLException: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified

Please , tell me where i am doing wrong?

Thanks

Re: read excel data

Posted By:   Sanjit_Bose  
Posted On:   Wednesday, March 28, 2001 04:45 AM

Steps required for making connection to Excel workbook thro' JDBC program.


1> Make a DSN by selecting your workbook as a datasource(ofcourse through the Excel Driver)


2> Open the DSN




3> Your Excel sheet must have field names in the 1st row.




The most quirious part is that what one should write in the SQL query.
and the answer is that one has to use the sheet name appended with a
'$' sign.




for refernce here goes a small program




import java.sql.*;



public class jdbcex

{

public static void main(String s[])

{

try{

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

Connection con = DriverManager.getConnection("Jdbc:Odbc:sanjit","","");//'sanjit' is the name of my DSN

Statement st = con.createStatement();

int p = st.executeUpdate("insert into "sheet2$" values ('xyz','sanjit')");//data inserted in sheet2

}

catch(Exception e)
{e.printStackTrace();}

}

}



By,

Sanjit Bose
Calcutta

sanjit_bose@yahoo.com
About | Sitemap | Contact