Database access examples
Perl scripts - stand-alone and CGI
Each link below gives a Perl script illustrating some kind of
database access. Comments are included to explain each. To be used, each
script needs to be configured with a database name, and most need a username and
password - see the comments. Each tries to access
information in a table called Panto using an SQL SELECT query; you
can test this by creating your own table called Panto in the
appropriate database, or you could customize the scripts to connect
to the Oracle database ora1a11, with your personal username and
password for that database and customize the SELECT to
query the table rb1.Panto (that's letter r, letter b,
digit one) which already exists with public access
permission.
- For running from a Unix/DOS command:
- A simple CGI script:
DBviaProxy.pl
- Click here
to run the script on www.cs (accessing Panto on CS)
Note
- The various techniques illustrated in these examples can be
combined, as appropriate for the circumstances. For example, if you run the
CGI version under control of a Web server on a Windows machine, then it
could use ODBC to connect to a database.
- The versions that use the Proxy server connection to campus Oracle
databases will run successfully on computers off-campus (with the
appropriate Perl installation).
- Perl on home PCs: Recommend that you install the most recent
version of ActivePerl from http://www.activestate.com/ . Depending on what you need to do, you will probably
need to download extra Perl packages for the database/remote access using
the DOS command line program ppm distributed with ActivePerl (probably
packages DBI, PlRPC, DBD-Oracle, DBD-ODBC).
Java applications
- First, a simple Java application for Windows that uses
the JDBC classes and the ODBC control panel to retrieve information from a
database configured with an ODBC Data Source Name. (Could be a local MS
Access database, a remote Oracle database, or other options.)
- Next the same application but making direct access to the Oracle
database CS in the Department.
- Finally the same application but making direct access to the Oracle
database Ora1a11 hosted centrally on Stunix.