Interacting with Databases
Establishing an ADBC Connection
14
// Obtain a list of accessible databases:
var databaseList = ADBC.getDataSourceList();
// Search the DataSourceInfo objects for the “Q32000Data” database:
if (databaseList != null) {
var DB = "";
for (var i=0; i<databaseList.length; i++)
if (databaseList[i].name == "Q32000Data") {
DB = databaseList[i].name;
break;
}
}
To establish the database connection, invoke the
ADBC
object’s
newConnection
method, which accepts the following parameters:
●
●
●
cDSN
: the Data Source Name (DSN) of the database
cUID
: the user ID
cPWD
: the password
The
newConnection
method returns a
connection
object, which encapsulates the
connection by providing methods which allow you to create a
statement
object, obtain
information about the list of tables in the database or columns within a table, and close the
connection.
In the following example, a connection is established with the
Q32000Data
database:
if (DB != "") {
// Connect to the database and obtain a Connection object:
var myConnection = ADBC.newConnection(DB.name);
}
The
connection
object provides the methods shown below in
Table 14.1:
T
ABLE
14.1
Connection Object
Method
Description
Closes the database connection
Creates a
statement
object used to execute SQL
statements
Retrieves information about the tables within the
database
Retrieves information about the various columns within a
table
close
newStatement
getTableList
getColumnList
Acrobat JavaScript Scripting Guide
239