对于jdbc程序,需要im连接excel数据库。连接已成功建立,但如果在其中输入值,则会出现“操作必须使用可更新查询”异常。
代码如下:
String url="jdbc:odbc:Sample"; //CHANGE THE DATABASE NAME
Connection conn= DriverManager.getConnection(url,"","");
PreparedStatement prepstat = null;
String insert="INSERT INTO [Sheet1$] ([AccountID], [ProjectID], [PositionID]) VALUES (?,?,?)";
prepstat= conn.prepareStatement(insert);
prepstat.setString(1, accountID);
prepstat.setString(2, projectID);
prepstat.setString(3, positionID);
prepstat.executeUpdate(); // this is where the exception occurs
最佳答案
您是否在连接字符串中特别声明该连接已读写?
我不熟悉JDBC,但ODBC应该是:
"Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=C:\MyFolder\MyWorkbook.xls; ReadOnly=False;"
excel默认为只读:http://support.microsoft.com/kb/257819