我在本地运行 R,数据库远程位于 MS SQL 服务器上。
我做我的准备工作:
require(RJDBC)
# initialize the driver
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver", "C:/files/sqljdbc4.jar")
# establish the connection
conn <- dbConnect(drv, "jdbc:sqlserver://DBserverName.example.com;instanceName=myINS;databaseName=myDB", "myUser", "myPass")
然后我检查是否可以读取某些表的标题:
dbListFields(conn,"table1")
作品。接下来我尝试阅读完整的表格:
dbReadTable(conn,"table1")
失败:
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for SELECT * FROM table1 (Invalid object name 'table1'.)
以 SQL 方式执行此操作也会失败:
sqlText <- paste("SELECT FROM \"table1\" ")
queryResults <- dbGetQuery(conn, sqlText)
失败:
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for SELECT * FROM "table1" (Invalid object name 'table1'.)
并且没有引号:
sqlText <- paste("SELECT FROM table1 ")
queryResults <- dbGetQuery(conn, sqlText)
失败:
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for SELECT * FROM table1 (Invalid object name 'table1'.)
知道为什么这会失败吗?