Adding JDBC Data Sources

 

 

 

After you've added at least one JDBC driver, you can create a Java Data Source. To add a new Java Data Source, click the Add... button which displays the Add Data Source dialog.

Figure 10: Add Data Source dialog

The Add Data Source dialog contains four input controls that let you specify the information needed to define a new Java Data Source as explained below:

Data Source Name. Enter the database name used in the VB code or the name of the database that a Form is bound to as the Data Source Name. If it is a file name, use the name of the file without the directory and without the file extension. If the connection is specified in the VB code to open a DAO database or an ADO Connection then you should examine the connection string argument.. During conversion, the system will parse the connection string for one of the following identifiers: Database, DSN, or Data Source. When one of these is found, it will strip off the directory name and the file extension if specified. This will then become the data source name that it will look for in the list of data sources defined by this dialog. For example, if you use the following to open a DAO database:

Set db = OpenDatabase("", False, False, ";DATABASE=C:\Databases\mydb.mdb")

or

Set db = OpenDatabase("C:\Databases\mydb.mdb")

Then you should enter mydb for the Data Source Name.

If one of these was not used for the database being used, then you must add a extra DSN identifier to your connection string. For example, if you had the following code:

Set db = OpenDatabase("", False, False, "driver={Microsoft ODBC for Oracle};CONNECTSTRING=mydb")

Assuming you want to call the data source, mydatabase, you should add a DSN=mydatabase. For example:

Set db = OpenDatabase("", False, False, "driver={Microsoft ODBC for Oracle};CONNECTSTRING=mydb;DSN=mydatabase")

Note: You must specify the actual string without using variables. For example, the following will not be properly understood:

Dim connStr As String
connStr = ";DATABASE=C:\Databases\mydb.mdb"
Set db = OpenDatabase("", False, False, connStr)

You should have the following instead:

Set db = OpenDatabase("", False, False, ";DATABASE=C:\Databases\mydb.mdb")


JDBC Driver. Click the arrow to open the drop-down list and select one of the previously added JDBC drivers. The driver you select will be used to connect to the database.


Database URL. Enter the URL specified in the documentation for the JDBC driver specified above. For example, the URL for the JDBC-ODBC driver supplied with Java is jdbc:odbc:dsn where dsn is the data source name specified in Windows ODBC Data Source Administrator (double-click on ODBC in the Control Panel) for the ODBC data source you are using.

If your documentation says something like "open a connection to the database named, mydatabase, with the JDBC getConnection method":

Connection conn = DriverManager.getConnection ("jdbc:oracle:oci7:@mydatabase", "scott", "tiger");

Take everything inside the first quoted string, jdbc:oracle:oci7:@mydatabase and put this as the Database URL.

Another Oracle example using their thin driver which is a Type IV driver that doesn't require Oracle Client to be installed on each client. The Oracle Thin driver will download all of the classes it needs and allow the Java client to talk straight to the database server located on the web server:

Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");

Take everything inside the first quoted string, jdbc:oracle:thin:@myhost:1521:orcl and put this as the Database URL. Note: the syntax after the ":@" is host:port:sid.