我会尝试使用不同的类型。
dbGetQuery 以查找和迭代数据库为基础,而不是操纵它的记录。
类似问题被问到before;
我找不到一个不错的 R 示例,但如果有帮助,可以找到一个不错的 java 示例 here:
编辑:
我找到了我所说的类型!花了我一段时间,无论如何 - sqlQuery 允许您运行几乎任何查询,即 - 数据库记录的更改。示例我修改自this 来源:
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.