Defining Connection Parameters
Go Up to Opening a Database Connection
Contents
The database URL and connection properties arguments to connect()
or getConnection()
must be defined before trying to create the connection.
Syntax for Specifying Database URLs
InterClient follows the JDBC standard for specifying databases using URLs. The JDBC URL standard provides a framework so that different drivers can use different naming systems that are appropriate for their own needs. Each driver only needs to understand its own URL naming syntax; it can reject any other URLs that it encounters. A JDBC URL is structured as follows:
jdbc:subprotocol:subname
The subprotocol names a particular kind of database connection, which is in turn supported by one or more database drivers. The DriverManager
decides which driver to use based on which subprotocol is registered for each driver. The contents and syntax of subname in turn depend upon the subprotocol. If the network address is included in the subname, the naming convention for the subname is:
//hostname:/subsubname
subsubname
can have any arbitrary syntax.
Defining an InterClient URL
InterClient URLs have the following format:
jdbc:interbase://server/full_db_path[?properties]
“InterBase” is the sub-protocol, and server is the hostname of the InterBase server. full_db_path
(that is, “sub-subname”) is the full pathname of a database file, including the initial slash (/). If the InterBase server is a Windows system, you must include the drive name as well. InterClient does not support passing any attributes in the URL. For local connections, use:
server = "localhost"
The “/” between the server and
full_db_path
is a delimiter. When specifying the path for a Unix-based database, you must include the initial “/” for the root directory in addition to the “/” for the delimiter.In a Unix-based database, the following URL refers to the database orders.ib
in the directory /dbs
on the Unix server accounts
.
dbURL = "jdbc:interbase://accounts//dbs/orders.ib"
In a Windows server, the following URL refers to the database customer.ib
in the directory /dbs
on drive C of the server support
.
dbURL = "jdbc:interbase://support/C:/dbs/customer.ib"
Defining the Connection Properties
Connection properties must also be defined before trying to open a database connection. To do this, pass in a java.util.Properties
object, which maps between tag strings and value strings. Two typical properties are “user” and “password.” First, create the Properties
object:
java.util.Properties properties = new java.util.Properties();
Now create the connection arguments. user and password are either literal strings or string variables. They must be the username and password on the InterBase database to which you are connecting:
properties.put (“user”, "sysdba"); properties.put (“password”, "masterkey");
Now create the connection with the URL and connection properties parameters:
java.sql.Connection connection = java.sql.DriverManager.getConnection(url, properties);