connect: connect

Description Arguments Details Value DBMS parameter details Examples

View source: R/Connect.R

Description

connect creates a connection to a database server .There are four ways to call this function:

Arguments

connectionDetails

An object of class connectionDetails as created by the createConnectionDetails function.

dbms

The type of DBMS running on the server. Valid values are

  • "oracle" for Oracle

  • "postgresql" for PostgreSQL

  • "redshift" for Amazon Redshift

  • "sql server" for Microsoft SQL Server

  • "pdw" for Microsoft Parallel Data Warehouse (PDW)

  • "netezza" for IBM Netezza

  • "bigquery" for Google BigQuery

  • "sqlite" for SQLite

  • "sqlite extended" for SQLite with extended types (DATE and DATETIME)

  • "spark" for Spark

user

The user name used to access the server.

password

The password for that user.

server

The name of the server.

port

(optional) The port on the server to connect to.

extraSettings

(optional) Additional configuration settings specific to the database provider to configure things as security for SSL. These must follow the format for the JDBC connection for the RDBMS specified in dbms.

oracleDriver

Specify which Oracle drive you want to use. Choose between "thin" or "oci".

connectionString

The JDBC connection string. If specified, the server, port, extraSettings, and oracleDriver fields are ignored. If user and password are not specified, they are assumed to already be included in the connection string.

pathToDriver

Path to a folder containing the JDBC driver JAR files. See downloadJdbcDrivers for instructions on how to download the relevant drivers.

Details

This function creates a connection to a database.

Value

An object that extends DBIConnection in a database-specific manner. This object is used to direct commands to the database engine.

DBMS parameter details

Depending on the DBMS, the function arguments have slightly different interpretations: Oracle:

Microsoft SQL Server:

Microsoft PDW:

PostgreSQL:

Redshift:

Netezza:

Impala:

SQLite:

Spark:

To be able to use Windows authentication for SQL Server (and PDW), you have to install the JDBC driver. Download the **version 9.2.0** .zip from [Microsoft](https://docs.microsoft.com/en-us/sql/connect/jdbc/release-notes-for-the-jdbc-driver?view=sql-server-ver15#92-releases) and extract its contents to a folder. In the extracted folder you will find the file sqljdbc_9.2/enu/auth/x64/mssql-jdbc_auth-9.2.0.x64.dll (64-bits) or ssqljdbc_9.2/enu/auth/x86/mssql-jdbc_auth-9.2.0.x86.dll (32-bits), which needs to be moved to location on the system path, for example to c:/windows/system32. If you not have write access to any folder in the system path, you can also specify the path to the folder containing the dll by setting the environmental variable PATH_TO_AUTH_DLL, so for example Sys.setenv("PATH_TO_AUTH_DLL" = "c:/temp") Note that the environmental variable needs to be set before calling connect for the first time.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Not run: 
conn <- connect(
  dbms = "postgresql",
  server = "localhost/postgres",
  user = "root",
  password = "xxx"
)
dbGetQuery(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)

conn <- connect(dbms = "sql server", server = "RNDUSRDHIT06.jnj.com")
dbGetQuery(conn, "SELECT COUNT(*) FROM concept")
disconnect(conn)

conn <- connect(
  dbms = "oracle",
  server = "127.0.0.1/xe",
  user = "system",
  password = "xxx",
  pathToDriver = "c:/temp"
)
dbGetQuery(conn, "SELECT COUNT(*) FROM test_table")
disconnect(conn)

conn <- connect(
  dbms = "postgresql",
  connectionString = "jdbc:postgresql://127.0.0.1:5432/cmd_database"
)
dbGetQuery(conn, "SELECT COUNT(*) FROM person")
disconnect(conn)

## End(Not run)

DatabaseConnector documentation built on Nov. 18, 2021, 5:08 p.m.