Reputation: 351
I have an Append query object in my Access database. I can call all Select query objects, with no issues.
But if the query inserts into db, I can not call it from Java, the error is "lack of privileges or object not found".
How can I call the insert/append query from my Java code?
Upvotes: 2
Views: 506
Reputation: 123399
UCanAccess can execute saved "action queries" in Access (Append queries, Update queries, and Delete queries) using a CallableStatement
object.
If the saved query has no parameters then the code is simply
try (CallableStatement s = conn.prepareCall("{call MyAppendQuery()}")) {
s.execute();
}
(Note that the empty parentheses ()
after the query name are required.)
For a saved action query with parameters, the code is like this
try (CallableStatement s = conn.prepareCall("{call MyAppendQuery(?,?)}")) {
s.setString(1, "Hello from UCanAccess");
s.setTimestamp(2, java.sql.Timestamp.valueOf("2011-01-31 14:15:16"));
s.execute();
}
Upvotes: 1