代わりに別のタイプを使用してみます。
dbGetQuery
DB のレコードを操作するのではなく、DB を検索して反復処理することに基づいています。以前にも同様の質問がありました。
素敵な R の例を見つけることができませんでしたが、それが役立つ場合は、素敵な Java の例をここで見つけることができます。
編集:
話題のタイプを発見!とにかく、しばらく時間がかかりました-sqlQuery
ほとんどすべてのクエリ、つまりDBレコードの変更を実行できます。このソースから変更した例:
res <- sqlQuery(con1,"DELETE TABLE TESTDATA", errors=FALSE)
# res will now hold the result of the query.
# -1 means error, otherwise iteration is sucessful, and it will hold the number of rows affected.
if (res == -1){ #if something messed up
cat ("An error has occurred.\n")
msg <- odbcGetErrMsg(con1) #Use your connection for this.
print (msg)
} else {
cat ("Table was deleted successfully.\n")
}
編集2:
RODBC と混同してしまいましたが、RJDBC の代替手段も見つけたので、心配する必要はありません。と呼ばれdbSendUpdate
ます。例:
# Assuming you have the connection saved as conn; these example shows how to use dbSendUpdate to create tables and insert values.
# You could use it with every non-selective query, that is, which manipulates the record (update,delete,insert,drop etc.)
# create table, with dbSendUpdate:
dbSendUpdate(conn, "CREATE TABLE foo(a INT,b VARCHAR(100))")
# insert value, bind parameters to placeholders in statement:
dbSendUpdate(conn, "INSERT INTO foo VALUES(?,?)", 42, "bar")
# feel free to modify the query itself, these are just example values.