Making database connections
The connection process
The Web ActiveX and Transaction Object controls make database
connections using JDBC. Their Java classes interact with the Java
classes of the database vendor’s JDBC interface. The vendor’s
classes interact with the database.
JDBC driver from a database vendor
The classes for the JDBC database driver you plan to use must
be available to the user’s browser. If the user does not
have them installed already, you can set up the Web page so that
they are downloaded and installed just as you do for the Web ActiveX.
To have the JDBC driver classes installed automatically, you
can:
- Convert the database
vendor’s Java classes into a CAB file. You can use a Microsoft
utility called CABARC to do the conversion. The classes can be in
a ZIP archive or directory tree. - Add an Object element with a CODEBASE attribute
for the CAB file to the Web page.
The browser downloads the CAB file and adds the classes to
its internal class path. There is no change made to the CLASSPATH
environment variable.
If you want to use the JDBC driver when you are defining DataWindow objects,
you need to do some additional installation, such as putting the
JDBC driver classes on the system class path.
For more information, see Connecting to Your Database
for
PowerBuilder or the online Help for DataWindow Builder.
Connection properties
The connection information for the Transaction Object or Web
ActiveX is set as Param elements enclosed in the Object element.
Whether you use a separate Transaction object or the internal connection
properties of the Web ActiveX, the connection properties are the
same:
| Param name | Meaning | Typical value |
|---|---|---|
| LogID | The ID needed to log in to the database | dba(default ID for ASA databases) |
| LogPass | The password needed to log in to the database |
sql(default password for ASA databases) |
| dbParm | A string specifying the Java classes for the driver and the URL for the database |
For the JConnect driver: Driver=’com.sybase.jdbc.SybDriver’,URL=’jdbc:sybase:Tds:199.1.1.1:9999/mydatabase’ |
| Lock | The isolation level of the connection | Vendor-specific values |
| AutoCommit | Whether a commit occurs immediately after the database is updated |
False (default) |
About dbParm
For JDBC drivers, the dbParm property specifies essential
connection information. Its value is a string that contains at least
two values. Those values identify the driver you want to use and
the URL of the database, in a format understood by the driver.
The format is:
|
1 |
Driver='<i>JDBCclassname</i>',URL='<i>database_url</i>' |
To find the class name for Driver and the format of the database
URL, check the documentation from the DBMS vendor.
For examples of setting these properties in Param elements,
see “Properties and Param elements”.
Tips for using JConnect
JConnect in the development environment
If you want to use JConnect when you define DataWindow objects,
put the Java classes for JConnect on the class path. An instruction
like this should appear in AUTOEXEC.BAT:
|
1 |
SET CLASSPATH=d:Program FilesSybaseShared<br /> JConnect40 |
JConnect with SQL Anywhere 5.0
If you are accessing a SQL Anywhere 5.0 database, you need
Open Server Gateway. You can configure the Open Server Gateway Starter
to start one or more SQL Anywhere databases.
Adaptive Server Anywhere 6.0 does not require Open Server
Gateway.
Connecting and retrieving data
To connect and retrieve data, you must write a script. The
script can belong to a Retrieve button or you can have the retrieval
occur automatically by putting the code in the window’s
onLoad script.
For example, to connect and retrieve data for a Web ActiveX
named dw_1, using a DataWindow Transaction Object control
named trans_1, your script would be similar to this:
|
1 |
trans_1.Connect( ); |
|
1 |
dw_1.SetTransObject( trans_1 ); |
|
1 |
dw_1.Retrieve( ); |
When you use the internal transaction properties, the Web
ActiveX makes the connection automatically. The script can be simpler,
like this:
|
1 |
dw_1.Retrieve( ); |