4 jdbc — Load, write, or view data from a database with a Java API
Options for jdbc connect and jdbc add
jar("JarFileName") specifies the JDBC driver JAR file installed along your ado-path. Either jar()
or jarpath() is required with jdbc add. Also, if DataSourceName is not specified, either jar()
or jarpath() is required with jdbc connect for jdbc showdbs, jdbc showtables, jdbc
describe, jdbc load, jdbc insert, and jdbc exec to work. jar() may not be combined
with jarpath().
jarpath("DirectoryName") specifies the directory where the JDBC driver JAR files are installed along
your ado-path. Either jarpath() or jar() is required with jdbc add. Also, if DataSourceName is
not specified, either jarpath() or jar() is required with jdbc connect for jdbc showdbs, jdbc
showtables, jdbc describe, jdbc load, jdbc insert, and jdbc exec to work. jarpath()
may not be combined with jar().
driverclass("ClassName") specifies the Java class name stored in the JDBC driver JAR file installed
along your ado-path. driverclass() is required with jdbc add. Also, if DataSourceName is not
specified, driverclass() is required with jdbc connect for jdbc showdbs, jdbc showtables,
jdbc describe, jdbc load, jdbc insert , and jdbc exec to work.
url("URL") specifies the URL to the database the user is attempting to establish the connection to.
url() is required with jdbc add. Also, if DataSourceName is not specified, url() is required
with jdbc connect for jdbc showdbs, jdbc showtables, jdbc describe, jdbc load, jdbc
insert, and jdbc exec to work. The driver URL syntax is as follows:
jdbc:Database type://Host:Port/Database name?connection properties
user("UserID") specifies the user ID of the user attempting to establish the connection to a database.
user() is required with jdbc add. Also, if DataSourceName is not specified, user() is required
with jdbc connect for jdbc showdbs, jdbc showtables, jdbc describe, jdbc load, jdbc
insert, and jdbc exec to work.
password("Password") specifies the password of the user attempting to establish the connection to
a database. password() is required with jdbc add. Also, if DataSourceName is not specified,
password() is required with jdbc connect for jdbc showdbs, jdbc showtables, jdbc
describe, jdbc load, jdbc insert, and jdbc exec to work.
connprop("ConnectionProperty") specifies the driver-specific connection properties. A connection
property is a key value pair that is separated by a colon and delimited by a semicolon. For example,
jdbc connect, ... connprop("characterEncoding:ISO8859-1;")
These properties can also be set in the url() option.
clear clears the current connection settings from memory. This option may only be specified with
jdbc connect and may not be combined with any other connect options.
Options for jdbc load
table("TableName") specifies the name of the table stored in a specified database. Either the
table() option or the exec() option—but not both—is required with the jdbc load command.
exec("SqlStmtList") allows you to issue an SQL SELECT statement to generate a table to be read
into Stata. Multiple SQL statements can be issued, with the last SQL statement being a SELECT.
Each statement should be delimited by a semicolon. For example,
local sql ///
"CREATE TEMPORARY TABLE t(a INT, b INT); INSERT INTO t VALUES (1,2); ///
SELECT * FROM t;"
jdbc load, exec("‘sql’")