RH2 (version 0.2.4)

H2: H2 engine

Description

H2 creates a new DBI driver that can be used to start connections.

Usage

H2(driverClass='org.h2.Driver', 
	identifier.quote="\"", jars = getOption("RH2.jars"), …)

Arguments

driverClass

name of the Java class of the driver to load. If empty, it is assumed that corresponding drivers were loaded by other means.

identifier.quote

character to use for quoting identifiers in automatically generated SQL statements or NA for no quoted identifiers.

jars

pathname to H2 jar file. If omitted it will use the version of H2 included in RH2.

further arguments passed to .jpackage

Value

Returns a H2Driver object that can be used in calls to dbConnect.

Details

The H2 function initializes the Java VM, loads the H2 driver and creates a proxy R object which can be used to a call dbConnect which actually creates a connection.

It handles "integer", "Date", chron "times", "POSIXct" and "numeric" classes using the H2 types of "integer", "date", "time", "timestamp" and "double precision". All other R classes are converted to "character" and stored as varchar(255).

See Also

dbConnect

Examples

Run this code
# NOT RUN {
library(RJDBC)

con <- dbConnect(H2(), "jdbc:h2:~/test", "sa", "")

# create table, populate it and display it
s <- 'create table tt("id" int primary key, "name" varchar(255))'
dbSendUpdate(con, s)
dbSendUpdate(con, "insert into tt values(1, 'Hello')")
dbSendUpdate(con, "insert into tt values(2, 'World')")
dbGetQuery(con, "select * from tt")

# transfer a data frame to H2 and then display it from the database
dbWriteTable(con, "BOD", BOD)
dbGetQuery(con, "select * from BOD")

dbDisconnect(con)

# connect to a different version of H2 and show version
con <- dbConnect(H2(jars = "c:/tmp2/h2-1.3.155.jar"))
s <- "select VALUE from INFORMATION_SCHEMA.SETTINGS where NAME = 'info.VERSION'"
dbGetQuery(con, s)
dbDisconnect(con)

# }

Run the code above in your browser using DataLab