Re: How to extract data to and from microsoft excel on to the browser ?
Posted By:
Sanjit_Bose
Posted On:
Monday, April 23, 2001 11:14 PM
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 curious 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
You can put this code in your Servlet or JSP
import java.sql.*;
public class jdbcexcel
{
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