Skip to Content
0
Former Member
Jan 10, 2008 at 06:47 AM

values not getting inserted into excel sheet

16 Views

The main purpose of the application that I am going to develop is

I created a form which consists of two input fields and a button using a tool by name NWDS which is made by adding some plugins to The ECLIPSE tool

Once the user enters the data in the input fields and clicks on the button the data must get inserted in the EXCEL sheet which is stored on my desktop

DETAILS OF EXCEL SHEET

Name: empdetails.xls

Fields : EmpID ,EmpName

Java code which I have written is

Here ACTION1 is the action created for the button

Here first I fetch the data in the inputfields using getEMPID() and getEMPNAME()

Then I tried to create a connection to access the excel sheet

Then wrote the insert query.

How I got the ExcelJDBCTest?

Click start-àSettingsàControlPanel

Double click on ODBC

Click on SystemDSN.

Click Add

In the installed ODBC Drivers list select MICROSOFT EXCEL DRIVER

Clik Ok

In the Data Source Name field spreadsheet alias (ExcelJDBCTest)

Click on Select Workbook

Select the Path and filename (empdetails.xls)

Click on OK

Click on Ok in the ODBC MicrosoftExcel setup window

Click close

public void onActionACTION1(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionACTION1(ServerEvent)

String eid = wdThis.wdGetContext().currentContextElement().getEMPID();

String ename = wdThis.wdGetContext().currentContextElement().getEMPNAME();

try {

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

Connection con = DriverManager.getConnection("jdbc:odbc:ExcelJDBCTest");

String sqlstmt = "INSERT INTO values(?,?)";

PreparedStatement stmt = con.prepareStatement(sqlstmt);

stmt.setString(1,eid);

stmt.setString(2, ename);

stmt.executeUpdate();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Once I execute the above code I do not see the values getting inserted into the excel sheet

Thanks in advance