By Donald Bales
Price: $49.99 USD
£28.50 GBP
Cover | Table of Contents | Colophon
DriverManager. The rest of
the core API is a set of interfaces.
DriverManager is used to load a JDBC
Driver. A Driver is a software
vendor's implementation of the JDBC API. After a driver is
loaded, DriverManager is used to get a
DriverManager. The rest of
the core API is a set of interfaces.
DriverManager is used to load a JDBC
Driver. A Driver is a software
vendor's implementation of the JDBC API. After a driver is
loaded, DriverManager is used to get a
Connection. In turn, a
Connection is used to create a
Statement, or to create and prepare a
PreparedStatement or
CallableStatement. Statement
and PreparedStatement objects are used to execute
SQL statements. CallableStatement objects are used
to execute stored procedures. A Connection can
also be used to get a DatabaseMetaData object
describing a database's functionality.
Statement or PreparedStatement
are returned as a ResultSet. A
ResultSet can be used to get the actual returned
data or a ResultSetMetaData object that can be
queried to identify the types of data returned in the
ResultSet.
Struct
is a weakly typed object that represents a database object as a
record. A Ref is a reference to an object in a
database. It can be used to get to a database object. An
Array is a weakly typed object that represents a
database collection object as an array. The
Any time two different programs run in two separate operating-system processes in which one program requests services from the other, you have a client/server relationship.
import statements to your Java program so the
compiler will know where to find the classes you'll be using in
your Java code.
DriverManager object's
getConnection( ) method to establish a database
connection.
Import
statements tell the Java compiler
where to find the classes you reference in your code and are placed
at the very beginning of your source code. To use the standard JDBC
package, which allows you to select, insert, update, and delete data
in SQL tables, add the following imports to your
source code:
import java.sql.* ; // for standard JDBC programs import java.math.* ; // for BigDecimal and BigInteger support
import statement in your program:
import oracle.jdbc2.* // for Oracle interfaces equivalent to
// JDBC 2.0 standard package for JDK 1.1.x
import statement.
imports shown here you'll have
to explicitly identify each class file with its full package path and
name. For example, with try-catch-finally control block similar to
PL/SQL's BEGIN-EXCEPTION-END block. The
try
statement encloses a block of code
that is "risky" -- in other words, which can throw an
exception -- and that you wish to handle in such a way as to
maintain control of the program in the event that an exception is
thrown. Exceptions thrown in a try block are
handled by a catch clause coded to catch an
exception of its type or one of its ancestors. For example, when
using JDBC, the exception type thrown is usually a
SQLException.
try statement can have any number of
catch clauses necessary to handle the different
types of exceptions that can occur within the try
block. A try block can also have a
finally clause. The finally
clause is always executed before control leaves the
try block but after the first applicable
catch clause. Here is the general form of a
try block:
try {
// Your risky code goes between these curly braces!!!
}
catch(Exception e) {
// Your exception handling code goes between these curly braces,
// similar to the exception clause in a PL/SQL block.
}
finally {
// Your must-always-be-executed code goes between these curly braces.
}|
JDK version
|
JDBC classes
|
National Language Support classes
|
|---|---|---|
|
JDK 1.1.x
|
classes111.zip
|
nls_charset11.zip
|
|
JDK version
|
JDBC classes
|
National Language Support classes
|
|---|---|---|
|
JDK 1.1.x
|
classes111.zip
|
nls_charset11.zip
|
|
JDK 1.2.x
|
classes12.zip
|
nls_charset12.zip
|
init( )
start( )
stop( )
destroy( )
TestAppletPolicy, you should follow
these steps:
copy c:\windows\ora81\jdbc\lib\classes12.zip TestAppletPolicy.zip
TestApplet:
init( ): loading OracleDriver for applet created at 2000-09-30 19:20:21.606 init( ): getting connection com.ms.security.SecurityExceptionEx[TestAppletInitDestroy.init]: cannot connect to "dssnt01"
init( ): loading OracleDriver for applet created at 2000-09-30 19:22:33.576 init( ): getting connection netscape.security.AppletSecurityException: security.Couldn't connect to 'dssnt01' with origin from 'dssw2k01'.
_ _jdbc_ _
to be used in a firewall's set of rules. This literal has been
coded into Net8-compatible firewalls to force the lookup of the IP
address. If you inadvertently add this hostname to a firewall's
set of rules, any Oracle JDBC Thin driver will be able to pass
through the firewall.
init( )
init( ) method is invoked automatically before any
of the servlet's doXXX( ) methods can be
called.
doXXX( )
doGet(
), doDelete( ), doPost(
), and doPut( ) -- are called as
needed by web users to satisfy their dynamic content and form
processing needs.
destroy( )
init(
) method, open a connection at the beginning of each
doXXX( ) method, and close that connection at the
end of each doXXX( ) method.
DriverManager.getConnection(
)
method. With the server-side internal
driver you have two choices for a URL:
jdbc:oracle:kprb: jdbc:default:connection:
jdbc:oracle:kprb: as the
database URL when connecting through the server-side internal driver.
It has the same basic format as the rest of the URLs we've used
so far, and you can use it with any form of the
getConnection( ) method.
getConnection( ) to connect
through the server-side internal driver, any unneeded parameters will
be ignored. For example, if you pass a username and password, they
are simply ignored, because you are using a default connection. This
default connection was created when you connected to the database to
invoke your stored Java program. This means you can take a Java
program you've written to load data into Oracle, change the
driver type to kprb, load it into the database,
add an appropriate Java security policy to the database for file
access permissions, and execute the program without any major
modifications. Using getConnection( ) in this way
is a good programming practice. It means you'll consistently
use the same methodology to connect to the database for both internal
and external programs. This will make it easier for you, and
especially for the next guy or gal, to maintain your code.
XAConnection for distributed transaction
management
SocketPermission
security policy to allow your Java program to open a socket to the
external database. Once that policy is created, any program can use
it to open external connections. This also means that external
programs can access the current database without going through its
authentication system. That said, there may be times when an external
connection using the Thin driver is the right solution to a problem.
So let's examine the use of the Thin driver by working through
an example.
TestExternalConnection, uses the same
database URL syntax that is used with the client-side Thin driver.
System.out.println( ) and
System.err.println( ). Where does this output go?
System.out.println(
) and System.err.println( ) goes into a
trace file. That's not very useful, but you can make the output
go to the SQL*Plus screen buffer. The SQL*Plus screen buffer is the
buffer that the SYS.DBMS_OUTPUT.PUT_LINE stored procedure uses. To
send Java output to the SQL*Plus screen buffer, call the
SYS.DBMS_JAVA.SET_OUTPUT( ) stored procedure from within your Java
stored procedure. The syntax for doing that is:
SYS.DBMS_JAVA.SET_OUTPUT(BUFFER_SIZE IN NUMBER)
TestDbmsJavaSetOutput