I can read rows / columns perfectly, but I cannot update, insert, or delete.
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String myDB = "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=myExcelFile.xls;" + "DriverID=22;READONLY=false"; con = DriverManager.getConnection(myDB, username, password); stmt = con.createStatement(); stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = stmt.executeQuery("SELECT * FROM [users$]"); while (rs.next()) { String str = rs.getString("username"); System.out.println(str); rs.updateString("username", str + "UPDATED"); rs.updateRow(); } rs.close(); stmt.close(); con.close(); }catch(Exception e){System.out.println(e);}
This code crashes when it reaches rs.updateRow(); and displays this error:
java.sql.SQLException: [Microsoft] [Excel ODBC driver] Error in line
Note. Some people say this because READONLY is not set to false or 0, but I already did this, and the Excel file is also not set to read only
I have completed the following steps to apply the Update strings in ResultSet objects here: http://download.oracle.com/javase/tutorial/jdbc/basics/retrieving.html
source share