executeJDBC: Execute SQL Query on a JDBC-Compatible Database

Description Usage Arguments Details Value Note See Also Examples

Description

Executes a SQL command on a JDBC-Compatible database.

Usage

1
executeJDBC(sqlQuery, driverClass, con, user, password, keepAlive)

Arguments

sqlQuery

a string containing the SQL query to execute.

driverClass

a string containing the name of the Java class for required JDBC driver.

con

a string containing the JDBC connection string.

user

a string containing the user name with access to database.

password

a string containing the password for the given user name on the database.

keepAlive

a logical. If TRUE, keeps the database connection alive after executing the query. The default is FALSE.

Details

Executes the command on the database using the JDBC driver specified in driverClass. The required JDBC driver must be loaded in sjdbc before it is used. See loadJDBCDriver for details.

Database connections are closed by default after executing the query, unless keepAlive is set to TRUE. If keepAlive = TRUE, the connection remains open, and successive database commands can reuse the open connection if and only if the same values for driverClass, con, user, and password are supplied.

Value

returns the number of rows affected, if applicable.

Note

Some arguments can also be set using sjdbcOptions.

See Also

loadJDBCDriver, sjdbcOptions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
executeJDBC(driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver", 
            con="jdbc:sqlserver://qadb-s2k:1433;databaseName=testdb;user=testqa;password=testqa;", 
            user="testqa", password="testqa",
            sqlQuery="UPDATE TEST1 SET Weight = NULL WHERE Weight < 2500")

executeJDBC(driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver", 
            con="jdbc:sqlserver://qadb-s2k:1433;databaseName=testdb;user=testqa;password=testqa;", 
            user="testqa", password="testqa",
            sqlQuery="DROP TABLE TEST1")

## End(Not run)

sjdbc documentation built on May 1, 2021, 1:08 a.m.

Related to executeJDBC in sjdbc...