0

I am using below code to insert data into excel sheet.

public class SQLTest {

    Connection conn = null;
    Statement stmnt = null;
    ResultSet RS = null;
    String TestCaseWorkbook = null;
    String TestCaseSheet = null;
    public ResultSet getTestCases() throws SQLException{
        conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ= C:\\DurgeshProjectWork\\Selenium\\SeleniumTestNGWorkspace\\DevOps\\TestResults\\tmp\\020315_Index.xls");
        stmnt = conn.createStatement();

        String sSQL="insert into [TestSummary$] values ('First_value', 'seondValue', 'Addproductsandplaceorder', '6', '6', '0', 'firefox', 'Pass')";
        System.out.println("Result from function for sSQL = "+sSQL);
        RS = stmnt.executeQuery(sSQL);
        return RS;
    }

    public static void main (String [] args) throws SQLException
    {
        SQLTest st = new SQLTest();
        st.getTestCases();
        System.out.println("Result is = "+st.getTestCases() );
    }

}

However, I am getting below error message. Could anyone please help me to solve this issue

Result from function for sSQL = insert into [TestSummary$] values ('First_value', 'seondValue', 'Addproductsandplaceorder', '6', '6', '0', 'firefox', 'Pass')
Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Excel Driver] Operation must use an updateable query.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source)
    at testScripts.SQLTest.getTestCases(SQLTest.java:30)
    at testScripts.SQLTest.main(SQLTest.java:41)
Durgesh
  • 585
  • 4
  • 12
  • 33
  • Same like: http://stackoverflow.com/questions/5027899/excel-db-operation-must-use-an-updateable-query ? – pL4Gu33 Mar 02 '15 at 11:41
  • Exception says use an updatbale query. stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); – René Winkler Mar 02 '15 at 11:49
  • I referred the post which you recommended and modified the below statement conn = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ= 020315_Index.xls; ReadOnly=False"); Now my excel sheet is getting updated when it is open, and throwing below exception. Exception in thread "main" java.sql.SQLException: No ResultSet was produced at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source) at testScripts.SQLTest.getTestCases(SQLTest.java:30) – Durgesh Mar 03 '15 at 03:04

0 Answers0