我使用下面的代码将数据插入Excel工作表。
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() );
}
}
但是,我收到以下错误消息。有谁可以帮我解决这个问题
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)