[英]Connecting to oracle 10g database through R
I want to import data from SQL databases through RI tried too many times(almost 6 hrs) connecting to the server.我想通过 RI 从 SQL 数据库导入数据尝试了太多次(几乎 6 小时)连接到服务器。 I ran these command and it shows error:-我运行了这些命令,它显示错误:-
jdbcDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="ojdbc6.jar") jdbcDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="ojdbc6.jar")
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@//database.desktop-65l5f3s:1521/orcl", "username", "password") Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], : java.sql.SQLRecoverableException: IO Error: Unknown host specified jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@//database.desktop-65l5f3s:1521/orcl", "username", "password") .jcall(drv@jdrv, "Ljava/sql/ Connection;", "connect", as.character(url)[1], : java.sql.SQLRecoverableException: IO Error: Unknown host specified
I think there is a problem of driver but I am unable to resolve it.我认为驱动程序有问题,但我无法解决。
Below is what I did to connect R to the Oracle database下面是我为将 R 连接到 Oracle 数据库所做的工作
then run the code below in r然后在 r 中运行下面的代码
library(RJDBC)
## Loading required package: DBI
## Loading required package: rJava
# specify the driver type and location in your machine
jdbcDriver = JDBC("oracle.jdbc.OracleDriver",
classPath="C:/app/techsupport/product/11.2.0/client_1/jdbc/lib/ojdbc6.jar") # may be different on your machine, it's based on your JDK installation
# connect to the database
conn = dbConnect(jdbcDriver, "jdbc:oracle:thin:@//database.hostname.com:port/service_name", # get the database name, port, and service name from you DBA
user = YourUserName,
password = YourPassword)
# get office table using a query string
startTime <- Sys.time() # start timer
OfficeTable = dbGetQuery(conn, "select * from office")
# disconnect after working with database
dbDisconnect(conn)
## [1] TRUE
Sys.time() - startTime # calc time to import table
## Time difference of 0.1630161 secs
# take a look at the data
str(OfficeTable)
## 'data.frame': 373 obs. of 22 variables:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.