OpenConnection - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Driver

  

OpenConnection

  

opens a connection to a database

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

driver:-OpenConnection(url, username, password, opts )

Parameters

driver

-

Driver module

url

-

string; specifying the database

username

-

string; username for logging into the database

password

-

string or name; password to for logging into the database, 'none', or 'hidden'

opts

-

(optional) equations of the form option=value where option is one of readonly or isolation

Description

• 

OpenConnection opens a connection to a database using the JDBC Driver represented by driver.  The argument url specifies the database.   username is the name to use for logging in.  If password is a string then it is used as the password when logging in.  If password is none then no password is used when logging in.  If password is hidden, then a Maplet application, which allows the password to be entered without it appearing on screen, is opened.

• 

The value of url depends on the type of database, the JDBC driver and where the database is installed.  However the basic format is "jdbc:driver://hostname/DBName". driver is an identifier for the JDBC driver being used. hostname is the name of the computer on which the database is installed. hostname might also include a port number if the default port is incorrect. DBName is the name of the particular database. For the correct values, consult the documentation for the JDBC driver you are using.  For more information about JDBC drivers, see JDBC.

• 

For a general overview of using Database, see the usage page.

• 

OpenConnection accepts all the arguments that can be set on a Connection using SetOptions. The valid options are readonly and isolation.

  

readonly = true or false

  

The readonly optional argument informs the database that it can enable optimizations associated with a read-only connection.  The effect depends on the database.  Setting readonly=true may or may not prevent the execution of updates.  By default, connections are not opened read-only.

  

isolation = uncommittedread, committedread, repeatableread or serializable

  

The isolation optional argument determines how isolated transactions using this connection are from transactions occurring at the same time.

  

- At serializable isolation, dirty reads (reading uncommitted data from parallel transactions), non-repeatable reads (reading the same row multiple times producing different results due to parallel updates), and phantom reads (WHERE conditions matching different numbers of rows due to parallel updates) are all prevented.

  

- At repeatableread isolation, dirty reads and non-repeatable reads are prevented.

  

- At committedread, only dirty reads are prevented.

  

- At uncommittedread isolation, dirty reads are also allowed.

  

The default isolation is database specific.

• 

OpenConnection can be used to open multiple parallel connections to a single database or multiple connections to different databases (assuming they are all compatible with driver).

Examples

Load the JDBC driver and open a connection to the database.

driverDatabaseLoadDriverdriver=com.database.Driver,classpath=/path/to/jar/jdbc.jar:

conn1driver:-OpenConnectionjdbc:dbdriver://localhost/DBName,user1,passwd,isolation=serializable

conn1moduleoptionunload=Close;localhandle;exportExecuteQuery,ExecuteUpdate,CreateStatement,CreateCallableStatement,CreatePreparedStatement,Commit,Rollback,Close,SetOptions,GetOptions;end module

(1)

Open a read-only connection to the same database.

conn2driver:-OpenConnectionjdbc:dbdriver://localhost/DBName,user2,none,readonly=true

conn2moduleoptionunload=Close;localhandle;exportExecuteQuery,ExecuteUpdate,CreateStatement,CreateCallableStatement,CreatePreparedStatement,Commit,Rollback,Close,SetOptions,GetOptions;end module

(2)

Open a connection to a different database.

conn3driver:-OpenConnectionjdbc:dbdriver://localhost/DBName2,user3,secret

conn3moduleoptionunload=Close;localhandle;exportExecuteQuery,ExecuteUpdate,CreateStatement,CreateCallableStatement,CreatePreparedStatement,Commit,Rollback,Close,SetOptions,GetOptions;end module

(3)

Load a driver for a different kind of database and open a connection to that database.

driverDatabaseLoadDriverdriver=com.database2.Driver,classpath=/path/to/jar2/jdbc.jar:

conn4driver:-OpenConnectionjdbc:dbdriver2://localhost/DB2Name,user,passwd,isolation=serializable

conn4moduleoptionunload=Close;localhandle;exportExecuteQuery,ExecuteUpdate,CreateStatement,CreateCallableStatement,CreatePreparedStatement,Commit,Rollback,Close,SetOptions,GetOptions;end module

(4)

See Also

Database

Database[Connection]

Database[Connection][SetOptions]

Database[Driver]

Database[JDBC]

Database[usage]