Chapter 13: Using ADS from Java


Java developers have long been able to work with ADS using the JDBC- ODBC bridge, a class 1 JDBC (Java database connectivity) driver. The JDBC-ODBC bridge, however, is not convenient to use, and is even more difficult to deploy since it requires the additional installation and deployment of an appropriate ODBC (open database connectivity) driver. With the Advantage JDBC Driver, a class 4 JDBC driver first released in ADS version 7.0, working with ADS from Java is a breeze.

This chapter provides you with examples of using the Advantage JDBC Driver with the JDBC classes to perform a wide range of common data-related tasks—using the Java language in general, and Borland’s JBuilder in particular. As is the case with the other chapters in Part III, this discussion assumes that you are already familiar with Java programming.

ADS and Java

JDBC (Java database connectivity) is the core technology for accessing data from Java applications, applets, and servlets. Furthermore, using the JDBC Connector, available from Sun Microsystems, you can use this JDBC driver with any J2EE- compliant server. The Advantage JDBC Driver, named ADSDriver, is located in the com.extendedsystems.jdbc.advantage namespace. Once you have registered this driver and obtained a connection from the DriverManager, you access your ADS data using the classes and interfaces of the java.sql namespace.

The Advantage JDBC Driver is a class 4 JDBC driver. Unlike class 1, class 2, and class 3 JDBC drivers, a class 4 driver requires no additional libraries, beyond the Java driver itself, to connect to the underlying data. With the Advantage JDBC Driver, the connection to ADS is accomplished using sockets. Unlike the other Advantage data access mechanisms, the Advantage JDBC Driver does not require the services of the Advantage Client Engine (ace32.dll and libace.so are the ACE libraries for Windows and Linux, respectively).

The Advantage JDBC Driver communicates with ADS using TCP/IP port 6262 by default. If you need to communicate with ADS using a different port number on the server, you must change the server configuration. See the ADS help for information on how to configure your TCP/IP (transmission control protocol/Internet protocol) port number for the version of the ADS server that you are using.

Before you can use the Advantage JDBC Driver, you must install the adsjdbc.jar file and add it to your CLASSPATH environment variable. Java uses CLASSPATH to locate Java classes and other resources at runtime. The Advantage JDBC Driver installation will automatically install the JAR file. Depending on which environment you install the driver on, you may have to add the JAR file location to your CLASSPATH variable manually.

This chapter shows you how to access ADS using the Advantage JDBC Driver. This discussion is divided into four major sections. The first section describes common basic tasks, such as connecting to ADS, executing queries, and calling stored procedures.

Note

You cannot access ALS (Advantage Local Server) using the Advantage JDBC Driver. You must use ADS.

The second section shows you how to perform basic navigation with JDBC, and the third section demonstrates several basic administrative tasks, such as creating tables and granting rights to them. In the fourth and final section, you will find a brief discussion of using the Advantage JDBC Driver with JBuilder’s DataExpress components.

The use of the Advantage JDBC Driver is demonstrated in this chapter using Borland’s JBuilder, the most popular Java IDE (integrated development environment). Figure 13-1 shows the AdsJava.jpx project opened in JBuilder 9, with the public JFrame class, named MainFrame, displayed in the JBuilder designer.

click to expand
Figure 13-1: The MainFrame JFrame class in the JBuilder designer

ON THE CD

The sample code in this chapter can be found in the JBuilder project named AdsJava.jpx, available on this book’s CD-ROM (see Appendix B).

Even if you do not have a copy of JBuilder, you can still explore this project using the JDK (Java Development Kit) available from Sun Microsystems. Simply compile the two Java source files named Application1.java and MainFrame.java using javac.exe, the Java compiler. Once you have compiled these java files into byte-code class files, launch the application by running the Application1.class file using java.exe, the Java runtime launcher. The Application1 class contains the public, static main method entry point.




Advantage Database Server. The Official Guide
Advantage Database Server: The Official Guide
ISBN: 0072230843
EAN: 2147483647
Year: 2002
Pages: 129

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net