开发者

Excel DB: Operation must use an updateable query

开发者 https://www.devze.com 2023-02-11 05:20 出处:网络
for a jdbc program, im required to make a connection an excel da开发者_开发问答tabase. the connection is successfully made but wen entering values into it, its giving an \"Operation must use an update

for a jdbc program, im required to make a connection an excel da开发者_开发问答tabase. the connection is successfully made but wen entering values into it, its giving an "Operation must use an updateable query" exception.

here s the code:

        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


Did you specifically state that the connection was readwrite in your connection string?

I am not familiar with JDBC, but ODBC would be:

"Driver={Microsoft Excel Driver (*.xls)};" & _
"DBQ=C:\MyFolder\MyWorkbook.xls; ReadOnly=False;"

Excel is read-only by default: http://support.microsoft.com/kb/257819


It was just needed to uncheck the read only while creating the DSN.

0

精彩评论

暂无评论...
验证码 换一张
取 消