To connect the Java application to the database instance and to open a database session, you can use thejava.sql.DriverManager.getConnection method of the Java platform. This method supplies a Connection object that is connected to the database instance.
Alternatively, you can use the com.sap.dbtech.jdbcext.DataSourceSapDB class.
You can find more detailed information in the documentation on the Java platform, see sun.java.com.
●
You have started the X Server (see
X
Server, Starting the X
Server)
You have to start the X Server even if the Java application and the database instance are on the same computer.
● You have loaded the JDBC driver.
The java.sql.DriverManager.getConnection method has the mandatory parameter url (Connection URL) that can contain the following connection options.
Connection Options
Option |
Default Value |
Description |
acceptServerCertificateAlways |
off |
Only for SSL connections Determines whether the database system checks if the SSL certificate of the database computer is contained in the list of the trusted certificates and whether it is still valid Possible values: off: The database system checks the SSL certificate. on: The database system does not check the SSL certificate. |
autocommit |
on |
AUTOCOMMIT mode on: The database system ends every SQL statement automatically with a COMMIT. off: You must end transactions explicitly with the commit () and rollback () methods. |
cache |
- |
Specifies, for which SQL statements in Prepared Statements the JDBC driver saves information (for example, on the used parameters) in a dedicated cache Possible values: ● all: all SQL statements ● Combination of the following letters s (SELECT statements) i (INSERT statements) u (UPDATE statements) d (DELETE statements) cache=iud The database system saves information on INSERT, UPDATE and DELETE statements in the cache. |
connectiontimeout |
0 |
Timeout for the connection (in milliseconds) The value 0 means that there is no timeout.
|
ignoreHostNameInServerCert |
off |
Only for SSL connections Determines, whether the database system compares the name of the database computer with the name specified in the SSL certificate Possible values: off: The database system compares the names. on: The database system does not compare the names. |
isolation |
- |
Isolation level for the connection You can specify the isolation level either as a character string or as an integer (depending how you have declared it in the java.sql.Connection class). You can enter the following character strings: TRANSACTION_READ_UNCOMMITTED | TRANSACTION_READ_COMMITTED | TRANSACTION_REPEATABLE_READ | TRANSACTION_SERIALIZABLE You can enter the
following integer values: see Concepts of the Database System, |
password |
- |
Password of the database user Be sure to
observe the use of upper and lower case, see Concepts of the Database
System, |
reconnect |
on |
RECONNECT mode Possible values: on: The system automatically reconnects to the database instance after a command timeout. off: There is no automatic new connection. |
sqlmode |
INTERNAL |
SQL mode ORACLE | INTERNAL |
timeout |
|
Timeout for the database session (in seconds) If you specify this
connection option, you override the timeout that has been configured for the
database instance with the special database parameter SESSION_TIMEOUT (see
Concepts
of the Database System, |
trace |
- |
<directory>/<jdbc_trace_file> If you specify this connection option, then the database system writes a JDBC trace in the <jdbc_trace_file> file in the directory <directory>. |
tracesize |
- |
Maximum number of lines in the JDBC trace file. If this number of lines is exceeded, the database system begins to overwrite the content of the JDBC trace file |
transport |
socket |
Communication method for communicating with the DBM server Possible values: socket: TCP/IP connection secure: SSL connection, see Setting Up an SSL Connection |
unicode |
false |
When you specify this connection option, the JDBC driver sends the user name, password and SQL statements in Unicode to the database instance |
user |
- |
Name of the database user |
Examples: Connecting to the Database Instance