OpenSQLConnection

OpenSQLConnection[src]
makes a connection to a named data source.
makes a connection to a data source described by a JDBC object.
opens a GUI for creating and managing named data sources.
Details and Options
- To use OpenSQLConnection, you first need to load DatabaseLink using Needs["DatabaseLink`"].
- The following options can be given:
-
"Name" "" name of the connection "Description" "" textual description of the connection "Username" "" username to use for connecting "Password" "" password to use for connecting "Location" "" location of the file that defines the connection "Catalog" Automatic location of the database catalog "Properties" {} key-value pairs, as rules, passed to JDBC driver "ReadOnly" Automatic set the connection to be read only "RelativePath" False indicates whether or not database location is specified relative to configuration (for file-based databases) "Timeout" $SQLTimeout timeout setting for operations, in seconds "TransactionIsolationLevel" Automatic set transaction isolation for the connection "UseConnectionPool" Automatic open the connection from a managed pool "Version" None version of the configuration file "AutoCommit" True set the autocommit mode for the connection
Examples
open allclose allBasic Examples (1)Summary of the most common use cases

https://wolfram.com/xid/0ciga77kvwby4stjm-djvc6r
If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in Using the Example Databases.
Open a connection to a named data source:

https://wolfram.com/xid/0ciga77kvwby4stjm-p6c


https://wolfram.com/xid/0ciga77kvwby4stjm-ots
Open a connection to a data source specified using JDBC:

https://wolfram.com/xid/0ciga77kvwby4stjm-wz7


https://wolfram.com/xid/0ciga77kvwby4stjm-gxm

https://wolfram.com/xid/0ciga77kvwby4stjm-p3f


https://wolfram.com/xid/0ciga77kvwby4stjm-q8d
If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the "DatabaseLink`DatabaseExamples`" package, as described in Using the Example Databases.
Options (10)Common values & functionality for each option
"Username" (1)
"Password" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-c0za6w
Specify username and password:

https://wolfram.com/xid/0ciga77kvwby4stjm-c9d


https://wolfram.com/xid/0ciga77kvwby4stjm-hnv
Use $Prompt to be prompted for the password:

https://wolfram.com/xid/0ciga77kvwby4stjm-vk4


https://wolfram.com/xid/0ciga77kvwby4stjm-fqt
"Catalog" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-4e2g0c
Implementation of catalogs varies significantly among RDBMS types and their drivers. In MySQL, for example, "Catalog" may be used to specify the database. Connect to the database sandbox in the MySQL installation on localhost:

https://wolfram.com/xid/0ciga77kvwby4stjm-lwovya

https://wolfram.com/xid/0ciga77kvwby4stjm-t55ubo

https://wolfram.com/xid/0ciga77kvwby4stjm-6n7mcs
Equivalently, specify the database in the connection URL:

https://wolfram.com/xid/0ciga77kvwby4stjm-onrlqq

https://wolfram.com/xid/0ciga77kvwby4stjm-sosjp6

https://wolfram.com/xid/0ciga77kvwby4stjm-44m08n
"Properties" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-ifuk8b
Additional settings may be passed to the JDBC driver by means of the "Properties" option. For example, Derby requires the property "create" be set to "true" for databases that do not already exist:

https://wolfram.com/xid/0ciga77kvwby4stjm-xqlska


With the property set, the connection opens normally:

https://wolfram.com/xid/0ciga77kvwby4stjm-s1l9x8


https://wolfram.com/xid/0ciga77kvwby4stjm-4qqvtq
Equivalently, set attributes in a connection URL:

https://wolfram.com/xid/0ciga77kvwby4stjm-q38ywx


https://wolfram.com/xid/0ciga77kvwby4stjm-lzgtcn
"ReadOnly" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-v06ee4
A read-only connection will not permit modification or creation of tables or records:

https://wolfram.com/xid/0ciga77kvwby4stjm-8ysuya


https://wolfram.com/xid/0ciga77kvwby4stjm-pjqagx



https://wolfram.com/xid/0ciga77kvwby4stjm-u7elwe
"RelativePath" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-eaoaqq
For file-based databases, supplied paths to resources are interpreted as relative to the current working directory if they are not absolute. Force a path interpretation relative to a given location using the "RelativePath" option:

https://wolfram.com/xid/0ciga77kvwby4stjm-z8ln5x


https://wolfram.com/xid/0ciga77kvwby4stjm-uybm13


https://wolfram.com/xid/0ciga77kvwby4stjm-zfjrvd
"Timeout" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-i492p2
A connection attempt will time out in $SQLTimeout seconds, which has a driver-dependent default. Override it with the "Timeout" option, supplying an integer number of seconds:

https://wolfram.com/xid/0ciga77kvwby4stjm-dpfd0t


"TransactionIsolationLevel" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-eanbod
Transactions on the opened connection are isolated using a driver-dependent default. Override it with the "TransactionIsolationLevel" option, supplying one of "ReadUncommitted", "ReadCommitted", "RepeatableRead", or "Serializable":

https://wolfram.com/xid/0ciga77kvwby4stjm-zft4cr


https://wolfram.com/xid/0ciga77kvwby4stjm-zeuou4


https://wolfram.com/xid/0ciga77kvwby4stjm-dkv13m


https://wolfram.com/xid/0ciga77kvwby4stjm-zotyz6
More information about transactions and isolation levels is available in the Transactions tutorial.
"UseConnectionPool" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-mddsr0
Set the "UseConnectionPool" option to open a connection in a managed pool. The pool will be created if it does not already exist:

https://wolfram.com/xid/0ciga77kvwby4stjm-x4za3

This is the pool object associated with the connection:

https://wolfram.com/xid/0ciga77kvwby4stjm-2kjp9r

Close the pool and any associated connections:

https://wolfram.com/xid/0ciga77kvwby4stjm-zefqhs
More information about connection pools is available in the Connection Pools tutorial.
"AutoCommit" (1)

https://wolfram.com/xid/0ciga77kvwby4stjm-f7p09z
Set the "AutoCommit" option to open a connection. Connecting database with default AutoCommit set to True.

https://wolfram.com/xid/0ciga77kvwby4stjm

Creating table and inserting data by enabling AutoCommit mode. Insertion operation takes more time when AutoCommit mode is enabled.

https://wolfram.com/xid/0ciga77kvwby4stjm

Connecting database by disabling AutoCommit mode.

https://wolfram.com/xid/0ciga77kvwby4stjm

Insertion operation takes less time while performing bulk insert when AutoCommit is disabled.

https://wolfram.com/xid/0ciga77kvwby4stjm

Insertion is completed but not committed.

https://wolfram.com/xid/0ciga77kvwby4stjm

Other database connections are not able to see the changes before commit.

https://wolfram.com/xid/0ciga77kvwby4stjm

Committing the databases changes.

https://wolfram.com/xid/0ciga77kvwby4stjm

Other database connections are able to see the changes after commit.

https://wolfram.com/xid/0ciga77kvwby4stjm


https://wolfram.com/xid/0ciga77kvwby4stjm
Possible Issues (2)Common pitfalls and unexpected behavior

https://wolfram.com/xid/0ciga77kvwby4stjm-bcdguu
Not all JDBC drivers implement timeout-related methods. The "Timeout" option has no effect with certain drivers:

https://wolfram.com/xid/0ciga77kvwby4stjm-j33ms7



https://wolfram.com/xid/0ciga77kvwby4stjm-pk5tjm
Not all JDBC drivers implement all available settings for the "TransactionIsolationLevel" option. Here an opened connection reverts to the default isolation level:

https://wolfram.com/xid/0ciga77kvwby4stjm-2laogh


https://wolfram.com/xid/0ciga77kvwby4stjm-9qe1xt