Results 1 to 15 of 15
- 06-26-2011, 04:57 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 26
- Rep Power
- 0
error while using sql update statement
while running the following program i got a runtime error:
exception [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.
import java.io.*;
import java.sql.*;
public class database
{
public static void main(String args[])throws IOException
{
Connection con=null;
Statement stmt=null;
// ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Access" );
//String s="SELECT * FROM CUSTOMER";
stmt=con.createStatement();
String s1 = "insert into CUSTOMER values('adf','dsf')";
if (stmt.executeUpdate(s1)>0)
System.out.println("record inserted");
else
System.out.println("record insertion failed");
// rs=stmt.executeQuery(s);
// while (rs.next())
// {
// System.out.println(" " + rs.getString("name"));
// }
}
catch(Exception e)
{
System.out.println("exception "+e.getMessage());
}
}
}
plz help me solve the problemLast edited by jttslg; 06-26-2011 at 05:03 PM.
- 06-26-2011, 05:15 PM #2
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
try stmt.executeQuery() instead
- 06-26-2011, 05:42 PM #3
I don't do JDBC, but I don't see anywhere in that code where you tell Access which database (.mdb) to use.
@d3n1s: the question is about inserting a record, not about querying a table.
db
- 06-26-2011, 05:49 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,392
- Blog Entries
- 7
- Rep Power
- 17
Last edited by JosAH; 06-26-2011 at 05:55 PM. Reason: typo ...
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-26-2011, 10:41 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
You're right db i guess i misread. Before i began using hibernate i had the same approach to inserting a record into mysql and the method he uses work fine. Are you able to run a simple select query to return a rowset using this connection object? As in :
Java Code:stmt = con.createStatement(); String sql = "SELECT max(id) as id FROM tblPerson"; ResultSet rs = stmt.executeQuery(sql); rs.first(); Id = rs.getInt("id") + 1; rs.close();
- 06-27-2011, 03:09 AM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
- 06-27-2011, 11:18 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
That's fine. It's the syntax for the jdbc-odbc bridge. So long as the OP has an ODBC source defined as Access then that'll work.
Nope. You don't have to have any parameters on a createStatement() command. I rarely bother, as the default result set is usually OK.
- 07-01-2011, 03:27 AM #8
Member
- Join Date
- Mar 2010
- Posts
- 26
- Rep Power
- 0
- 07-01-2011, 09:26 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Have you declared an odbc data source called Access?
If not then you need to do that.
I'm sure there'll be some Microsoft documentation on how to do that.
- 07-01-2011, 05:15 PM #10
Member
- Join Date
- Mar 2010
- Posts
- 26
- Rep Power
- 0
- 07-01-2011, 05:17 PM #11
Member
- Join Date
- Mar 2010
- Posts
- 26
- Rep Power
- 0
- 07-02-2011, 09:51 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
OK, then give us the full error message with stack trace.
You'll have to change your catch block to use printStackTrace().
- 07-02-2011, 04:40 PM #13
Member
- Join Date
- Mar 2010
- Posts
- 26
- Rep Power
- 0
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java :3110)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcSt atement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Jdbc OdbcStatement.java:288)
at database.main(database.java:18)
BUILD SUCCESSFUL (total time: 1 second)
- 07-03-2011, 09:08 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
Looks like your Access db might be already open?
Something somewhere is marked as read only.
- 07-03-2011, 10:38 PM #15
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
This topic was cross posted to CodeRanch. The OP has not posted anything new in either topic, however it is probably worth looking in the other topic to see if there is anything new.
Similar Threads
-
oracle update statement within the resultset is not working.pls see code.
By renu in forum New To JavaReplies: 1Last Post: 05-17-2011, 09:43 AM -
fcpred.class update error
By Fulltimer2011 in forum Advanced JavaReplies: 0Last Post: 03-24-2011, 07:41 PM -
Error in JDBC batch update
By murali23krishna in forum JDBCReplies: 8Last Post: 02-21-2011, 11:42 AM -
issue with update on table and prepared statement
By hacktorious in forum JDBCReplies: 1Last Post: 01-10-2011, 01:44 AM -
Update statement not working.
By OMFGITSROHIT in forum JDBCReplies: 5Last Post: 04-08-2010, 01:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks