Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
683 views
in Technique[技术] by (71.8m points)

java - Excel DB: Operation must use an updateable query

for a jdbc program, im required to make a connection an excel database. 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:MyFolderMyWorkbook.xls; ReadOnly=False;"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...