Tuesday, November 6, 2007

Rowsets in JAVA

A javax.sql.RowSet object encapsulates a set of rows that have been retrieved
from a tabular data source. Because the RowSet interface includes an event
notification mechanism and supports getting and setting properties, every RowSet
object is a JavaBeansTM component. This means, for example, that a rowset can be
used as a JavaBeans component in a visual JavaBeans development environment. As
a result, a RowSet instance can be created and configured at design time, and its
methods can be executed at run time.

Rowsets at Design Time

Properties

The RowSet interface provides a set of JavaBeans properties that allow a RowSet
instance to be configured to connect to a data source and retrieve a set of rows.
CODE EXAMPLE

Setting properties for a RowSet object

sets some properties for the RowSet object rset.
rset.setDataSourceName("jdbc/SomeDataSourceName");
rset.setTransactionIsolation(
Connection.TRANSACTION_READ_COMMITTED);
rset.setCommand("SELECT NAME, BREED, AGE FROM CANINE");


The data source name property is used by a RowSet object to look up a
DataSource object in a JNDI naming service. (Relational databases are the most
common type of data source used by rowsets.) The DataSource object is used to
create a connection to the physical data source that it represents. The transaction
isolation property specifies that only data that was produced by committed
transactions may be read by the rowset. Lastly, the command property specifies the
command that will be executed to retrieve a set of rows. In this case, the NAME,
BREED, and AGE columns for all rows in the CANINE table are retrieved.

Events

RowSet components support JavaBeans events, which allows other JavaBeans
components in an application to be notified when an event on a rowset occurs. A
component that wishes to register for RowSet events must implement the
RowSetListener interface. Event listeners are registered with a rowset by calling
the addRowSetListener method as shown below. Any number of listeners may be
registered with an individual RowSet object.

Adding a listener to a RowSet object

adds one listener to
the RowSet object rset.
RowSetListener listener = ...;
rset.addRowSetListener(listener);


Rowsets can generate three different types of events:

1. Cursor movement events — indicate that the rowset’s cursor has moved
2. Row change events — indicate that a particular row has been inserted, updated or
deleted
3. Rowset change events — indicate that the entire contents of a rowset have
changed, which may happen, for example, when the method RowSet.execute
is called.

When an event occurs, the appropriate listener method is called behind the scenes to
notify the registered listener(s). If a listener is not interested in a particular kind of
event, it may implement the method for that event so that it does nothing. Listener
methods take a RowSetEvent object, which identifies the RowSet object that is the
source of the event.

Rowsets at Run Time

Parameters
The command property in CODE EXAMPLE 18-1 was set with a simple SQL command
that takes no input parameters, but it could also have been set with a command that
accepts input parameters. The RowSet interface provides a group of setter methods
for setting these input parameters.

CODE EXAMPLE
shows a command that takes a String input parameter. The
RowSet.setString method is used to pass the input parameter value to the
RowSet object rset. Typically, the command property is specified at design time,
whereas parameters are not set until run time when their values are known.

rset.setCommand("SELECT NAME, BREED, AGE FROM CANINE WHERE NAME = ?");
rset.setString(1, "spot");

CODE EXAMPLE

Setting parameters in a RowSet object’s command

Command Execution


A rowset may be filled with data by calling the RowSet.execute method. This
method uses the appropriate property values internally to connect to a data source
and retrieve some data. The RowSet interface includes the properties that are
needed to connect to a data source. The exact properties that must be set may vary
between RowSet implementations, so developers need to check the documentation
for the particular rowset they are using. The method execute throws an
SQLException if the necessary properties have not been set. The current contents of
a rowset, if any, are lost when the method execute is called.

Traversing a Rowset

The javax.sql.RowSet interface extends the java.sql.ResultSet interface, so
in many ways a rowset behaves just like a result set. In fact, most components that
make use of a RowSet component will likely treat it as a ResultSet object. A
RowSet object is simply a ResultSet object that can function as a JavaBeans

component. The code below shows how to iterate forward through a rowset. Notice
that since a rowset is a result set, this code is identical to the code that would be
used to iterate forward through a result set.

// iterate forward through the rowset

rset.beforeFirst();
while (rset.next()) {
System.out.println(rset.getString(1) + " " + rset.getFloat(2));
}

Printing all the rows in a two-column RowSet object
Other cursor movements, such as iterating backward through the rowset and
positioning the cursor on a specific row, are also done the same way they are for
result sets.

Relationship to Connectors::JAVA


The J2EE Connector Architecture 1.0 Specification defines a set of contracts that
allow a resource adapter to extend a container in a pluggable way. A resource
adapter provides connectivity to an external system from the application server. The
resource adapter’s functionality is similar to that provided by the JDBC interfaces
used in the J2EE platform to establish a connection with a data source. These
interfaces, which the Connector specification refers to as the service provider interface
(SPI), are the following:

  • DataSource
  • ConnectionPoolDataSource
  • XADataSource
Additionally, the Connector Architecture defines a packaging format to allow a
resource adapter to be deployed into a J2EE compliant application server.


System Contracts

The system contracts defined in the Connector specfication describe the interface
between an application server and one or more resource adapters. This interface
allows a resource adapter to be bundled in such a way that it can be used by any
application server that supports the system contracts.
The following standard contracts are defined between an application server and a
back end system:
  • A connection management contract that enables application components toconnect to a back end system.
The connection management contract is equivalent to the services described by
the JDBC interfaces DataSource and ConnectionPoolDataSource.
Chapter 19 Relationship to Connectors 168
  • A transaction management contract between the transaction manager and a backend system supporting transactional access to its resources.
The transaction contract is equivalent to the services described by the JDBC
interface XADataSource.
  • A security contract that enables secure access to a back end system.The security contract does not have an equivalent in the JDBC API.Authentication in the JDBC API always consists of providing a user name and apassword.
The JDBC specification does not make a distinction between its application
programming interface (API) and the SPI. However, a driver can map the JDBC
interfaces in the SPI to the Connector system contracts.


Mapping Connector System Contracts to
JDBC Interfaces

Driver vendors who want to supply JDBC drivers that use the Connector system
contracts have several options:

1. To write a set of classes that wrap a JDBC driver and implement the Connector
system contracts. Constructing these wrappers is fairly straightforward and
should allow JDBC driver vendors to provide resource adapters quickly enough
so that they are available when application server vendors have implemented the
Connector contracts.

2. To implement the Connector system contracts natively. This approach avoids the
overhead of wrapper classes, but the implementation effort may be more involved
and time-consuming. This alternative is a more long-term option.
Either approach will allow JDBC driver vendors to package their drivers as resource
adapters and get all the benefits of pluggability, packaging, and deployment.


Packaging JDBC Drivers in Connector
RAR File Format

Resource adapters can be packaged, along with a deployment descriptor, into a
Resource adapter ARchive, or RAR file. The RAR file contains the Java classes/
interfaces, native libraries, deployment descriptor, and other resources needed to
deploy the adapter.
The deployment descriptor maps the classes in the resource adapter to the specific
roles that they perform. The descriptor also details the capabilities of the resource
adapter in terms of what level of transactional support it provides, the kind of
security it supports, and so on.

CODE EXAMPLE is an example of a deployment descriptor for a JDBC driver. The
class com.acme.JdbcManagedConnectionFactory could be supported by an
implementation of javax.sql.XADataSource. The resource adapter section
contains information on the level of transaction support, the mechanism used for
authentication, and configuration information for deploying the data source in the
JNDI namespace.




’http://java.sun.com/j2ee/dtds/connector_1_0.dtd’>

Acme JDBC Adapter
Acme Software Inc
1.0
1.0
JDBC Database

com.acme.JdbcManagedConnectionFactorymanagedconnectionfactory-class>
javax.sql.DataSource
com.acme.JdbcDataSource
java.sql.Connection
com.acme.JdbcConnection
xa_transaction

XADataSourceName
java.lang.String
Chapter 19 Relationship to Connectors 170
jdbc/XAAcme


basic-password
javax.resource.security.PasswordCredentialcredential-interface>

false


CODE EXAMPLE 19-1 Example of a resource adapter deployment descriptor.
See the Connector specification for more details.

Data Type Conversion Tables:JAVA

The tables provided here describe the various mappings and conversions that
drivers must support.
TABLE B-1 JDBC Types Mapped to Java Types
This table shows the conceptual correspondence between JDBC types and Java
types. A programmer should write code with this mapping in mind. For example, if
a value in the database is a SMALLINT, a short should be the data type used in a
JDBC application.
All CallableStatement getter methods except for getObject use this mapping. The
getObject methods for both the CallableStatement and ResultSet interfaces
use the mapping in TABLE B-3.
TABLE B-2 Java Types Mapper to JDBC Types
This table shows the mapping a driver should use for the updater methods in the
ResultSet interface and for IN parameters. PreparedStatement setter
methods and RowSet setter methods use this table for mapping an IN parameter,
which is a Java type, to the JDBC type that will be sent to the database. Note that the
setObject methods for these two interfaces use the mapping shown in TABLE B-4.
TABLE B-3 JDBC Types Mapped to Java Object Types
ResultSet.getObject and CallableStatement.getObject use the mapping
shown in this table for standard mappings.
TABLE B-4 Java Object Types Mapped to JDBC Types
PreparedStatement.setObject and RowSet.setObject use the mapping
shown in this table when no parameter specifying a target JDBC type is provided.
TABLE B-5 Conversions by setObject from Java Obejct Types to JDBC Types
This table shows which JDBC types may be specified as the target JDBC type to the
methods PreparedStatement.setObject and RowSet.setObject.
B-176 JDBC 3.0 • July 2000
TABLE B-6 Type Conversions Supported by ResultSet getter Methods
This table shows which JDBC types may be returned by ResultSet getter methods.
A bold X indicates the method recommended for retrieving a JDBC type. A plain x
indicates for which JDBC types it is possible to use a getter method.
This table also shows the conversions used by the SQLInput reader methods, except
that they use only the recommended conversions.


JDBC Types Mapped to Java Types

JDBC Type JAVA Type

CHAR String
VARCHAR String
LONGVARCHAR String
NUMERIC java.math.BigDecimal
DECIMAL java.math.BigDecimal
BIT boolean
BOOLEAN boolean
TINYINT byte
SMALLINT short
INTEGER int
BIGINT long
REAL float
FLOAT double
DOUBLE double
BINARY byte[]
VARBINARY byte[]
LONGVARBINARY byte[]
DATE java.sql.Date
TIME java.sql.Time
TIMESTAMP java.sql.Timestamp
CLOB Clob
BLOB Blob
ARRAY Array
DISTINCT mapping of underlying type
STRUCT Struct
REF Ref
DATALINK java.net.URL
JAVA_OBJECT underlying Java class



Data Type Conversion
(
Standard Mapping from Java Types to JDBC Types)

JAVA Type JDBC Type


String CHAR, VARCHAR, or LONGVARCHAR
java.math.BigDecimal NUMERIC
boolean BIT or BOOLEAN
byte TINYINT
short SMALLINT
int INTEGER
long BIGINT
float REAL
double DOUBLE
byte[] BINARY, VARBINARY, or
LONGVARBINARY
java.sql.Date DATE
java.sql.Time TIME
java.sql.Timestamp TIMESTAMP
Clob CLOB
Blob BLOB
Array ARRAY
Struct STRUCT
Ref REF
java.net.URL DATALINK
Java class JAVA_OBJECT

The scalar functions are listed by category:JAVA

The JDBC API supports escape syntax for numeric, string, time, date, system, and
conversion functions on scalar values. These scalar functions may be used in SQL
strings as described in Section 13.4.1 “Scalar Functions” on page 13-109. The Open
Group CLI specification provides more information on the semantics of the scalar
functions. The scalar functions are listed below for reference.

If a DBMS supports a scalar function, the driver should also. Because scalar
functions are supported by different DBMSs with slightly different syntax, it is the
driver’s job either to map them into the appropriate syntax or to implement the
functions directly in the driver.

A user should be able to find out which functions are supported by calling metadata
methods. For example, the method DatabaseMetaData.getNumericFunctions
returns a comma separated list of the Open Group CLI names of the numeric
functions supported. Similarly, the method DatabaseMetaData.getStringFunctions returns a list of string functions supported, and so on.



NUMERIC FUNCTIONS

Function Name Function Returns

ABS(number) Absolute value of number
ACOS(float) Arccosine, in radians, of float
ASIN(float) Arcsine, in radians, of float
ATAN(float) Arctangent, in radians, of float
ATAN2(float1, float2) Arctangent, in radians, of float2 / float1
CEILING(number) Smallest integer >= number
COS(float) Cosine of float radians
C-184 JDBC 3.0 • July 2000
COT(float) Cotangent of float radians
DEGREES(number) Degrees in number radians
EXP(float) Exponential function of float
FLOOR(number) Largest integer <= number
LOG(float) Base e logarithm of float
LOG10(float) Base 10 logarithm of float
MOD(integer1, integer2) Remainder for integer1 / integer2
PI() The constant pi
POWER(number, power) number raised to (integer) power
RADIANS(number) Radians in number degrees
RAND(integer) Random floating point for seed integer
ROUND(number, places) number rounded to places places
SIGN(number) -1 to indicate number is < 0;
0 to indicate number is = 0;
1 to indicate number is > 0
SIN(float) Sine of float radians
SQRT(float) Square root of float
TAN(float) Tangent of float radians
TRUNCATE(number, places) number truncated to places places

STRING FUNCTIONS

Function Name Function Returns

ASCII(string) Integer representing the ASCII code value of the leftmost character in string
CHAR(code) Character with ASCII code value code, where code is between 0 and 255
CONCAT(string1, string2) Character string formed by appending string2 to string1; if a string is
null, the result is DBMS-dependent
DIFFERENCE(string1, Integer indicating the difference between the
string2) values returned by the function SOUNDEX for string1 and string2
INSERT(string1, start, A character string formed by deleting length
length, string2) characters from string1 beginning at start, and inserting string2 into
string1 at start
LCASE(string) Converts all uppercase characters in string to lowercase
LEFT(string, count) The count leftmost characters from string
LENGTH(string) Number of characters in string, excluding trailing blanks
LOCATE(string1, Position in string2 of the first occurrence of
string2[, start]) string1, searching from the beginning of string2; if start is specified,
the search begins from position start. 0 is returned if string2 does not contain
string1. Position 1 is the first character in string2.
LTRIM(string) Characters of string with leading blank spaces removed
REPEAT(string, count) A character string formed by repeating string count times
REPLACE(string1, string2, Replaces all occurrences of string2 in string1
string3) with string3
RIGHT(string, count) The count rightmost characters in string
RTRIM(string) The characters of string with no trailing blanks
Appendix C Scalar Functions C-185
SOUNDEX(string) Acharacter string, which is data source-dependent, representing the sound of
the words in string; this could be a four-digit SOUNDEX code, a phonetic
representation of each word, etc.
SPACE(count) A character string consisting of count spaces
SUBSTRING(string, start, A character string formed by extracting length
length) characters from string beginning at start
UCASE(string) Converts all lowercase characters in string to uppercase

TIME and DATE FUNCTIONS

Function Name Function Returns

CURDATE() The current date as a date value
CURTIME() The current local time as a time value
DAYNAME(date) A character string representing the day component of date; the name for the
day is specific to the data source
DAYOFMONTH(date) An integer from 1 to 31 representing the day of the month in date
DAYOFWEEK(date) An integer from 1 to 7 representing the day of the week in date; 1 represents
Sunday
DAYOFYEAR(date) An integer from 1 to 366 representing the day of the year in date
HOUR(time) An integer from 0 to 23 representing the hour component of time
MINUTE(time) An integer from 0 to 59 representing the minute component of time
MONTH(date) An integer from 1 to 12 representing the month component of date
MONTHNAME(date) A character string representing the month component of date; the name for
the month is specific to the data source
NOW() A timestamp value representing the current date and time
QUARTER(date) An integer from 1 to 4 representing the quarter in date; 1 represents January
1 through March 31
SECOND(time) An integer from 0 to 59 representing the second component of time
TIMESTAMPADD(interval, A timestamp calculated by adding count numcount,
timestamp) ber of interval(s) to timestamp; interval may be one of the following:
SQL_TSI_FRAC_SECOND, SQL_TSI_SECOND, SQL_TSI_MINUTE,
SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH,
SQL_TSI_QUARTER, or SQL_TSI_YEAR
TIMESTAMPDIFF(interval, An integer representing the number of interval
timestamp1, timestamp2) by which timestamp2 is greater than timestamp1; interval may be one of
the following: SQL_TSI_FRAC_SECOND, SQL_TSI_SECOND,
SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK,
SQL_TSI_MONTH, SQL_TSI_QUARTER, or SQL_TSI_YEAR
WEEK(date) An integer from 1 to 53 representing the week of the year in date
YEAR(date) An integer representing the year component of date
C-186 JDBC 3.0

SYSTEM FUNCTIONS

Function Name Function Returns

DATABASE() Name of the database
IFNULL(expression, value) value if expression is null;
expression if expression is not null
USER() User name in the DBMS

WebLogic Server Frequently Asked Questions::J2EE Connector Architecture

Q. Why do I get the following exception when viewing the JNDI tree?

isSerializable(class.javax.naming.Binding)
java.io.NotSerializableException:
java.io.PrintWriter at
java.io.ObjectOutputStream.OutputObject

A. The Weblogic Server JNDI implementation requires objects to be serializable, not referencable. A PrintWriter cannot be serialized and therefore should be declared transient.

Q. Is it possible to use the Oracle database rather than PointBase with the current implementation of the WebLogic J2EE Connector Architecture?

A. The sample provided contains a resource adapter that represents any database system. By default, configurations are set to use PointBase. In particular, the configuration properties in the weblogic-ra.xml file set a PointBase datasource. This can be replaced with Oracle settings.

Also, the resource adapter (in particular the ManagedConnectionFactory) must be implemented to support Oracle. The resource adapter provided in this sample makes use of the JDBC and therefore can support any database system which the resource adapter is configured to represent.

Q. When deploying a resource adapter (.rar) to WebLogic Server, are its classes placed in the WebLogic classpath?

For instance, I am deploying an EJB and a resource adapter (.rar), the EJB has no dependencies on the .rar because the EJB is writing to the common client interface (CCI). The EJB client application has sends/marshals as parameter classes that are defined in the .rar. For some reason the EJB's class loader hierarchy cannot find the definition of this .rar-specific class, even though the .rar is deploying successfully. I receive the following error on the EJB client:

java.rmi.UnmarshalException: error unmarshalling arguments; nested exception
is:
java.lang.ClassNotFoundException:
com.mycompany.InteractionSpecImpl

A. When you pass an instance of com.myclientcompany.server.eai.InteractionSpecImpl as an argument to your EJB, the appServer needs to de-serialize (unmarshal) the object under the EJB context, and it needs the required class for unmarshalling, inside the ejb-jar(raTester.jar). So if you include the interactionspecimpl class in your ejb-jar file, then you do not need to include those classes in your server's classpath.

Q. Why does WebLogic Server invoke the ManagedConnection.addConnectionEventListener() function whenever the sample EJB calls ConnectionFactory.getConnection() to connect to the EIS?

A. This is a requirement and is part of the contract between the Resource Adapter and the application server.

Q. Why do I get an exception when I compile my EJB to use a Resource Adapter that supports CCI?

I specify javax.resource.cci.ConnectionFactory in the resource-ref but I get the following exception when I attempt to compile my EJB:

weblogic.xml.process.SAXValidationException:
ejb-jar.enterprise-beans.session.resource-ref.res-type.
must be one of the values:
javax.sql.DataSource,javax.jms.QueueConnectionFactory,
javax.jms.TopicConnectionFactory,
java.net.URL,
javax.mail.Session
at
weblogic.ejb20.dd.xml.EjbJarLoader_EJB11.__post_84

A. Make sure your ejb-jar.xml is referencing the EJB2.0 DTD instead of the EJB1.1 DTD. The ConnectionFactory resource ref is only supported in the EJB 2.0 DTD.

Q. The BEA com.bea.adapter.dbms.cci.ConnectionImpl does not directly implement javax.resource.cci.Connection. Is there a work-around for this?

A. Yes. The BEA com.bea.adapter.dbms.cci.ConnectionImpl extends com.bea.adapter.cci.AbstractConnection; this in turn implements the Connection interface. The Proxy is constructed using the interfaces from the most-derived class (ConnectionImpl). The dumpFamilyTree printout shows that the getInterfaces call on the ConnectionImpl class does NOT include the Connection interface. However, the getInterfaces call on AbstractConnection does include the Connection interface.

The work-around is that the ConnectionImpl class must directly implement the interface class specified in the ra.xml file. (This might be a redundant statement in the code, particularly if it extends a class that has already implemented the class.) Then rebuild the adapter and try your test again.

JAVA Applets Questions

Q. What are the alternatives to using applets?

A. BEA supports the use of server-side applications with HTTP servlets and Java Server Pages (JSPs) as part of the J2EE platform. We recommend that before you develop new applications, consider using either servlets or JSPs. A well-designed series of interactive Web pages using servlets and Java Server Pages (JSPs) generally yield a faster and more reliable Web site.If you are currently using applets, you may find that most can be converted to Java applications using Java Web Start and you can continue using WebLogic Server. For information, go to Sun's Java Web Start site.

Q. Can I use a "native" two-tier driver for a browser applet?

A. No. Within an unsigned applet, you cannot load native libraries over the wire, access the local file system, or connect to any host except the host from which you loaded the applet. The applet security manager enforces these restrictions on applets as protection against applets being able to do unsavory things to unsuspecting users.

If you are trying to use jDriver for Oracle from an applet, then you are violating the first restriction. Your applet will fail when it attempts to load the native (non-Java layer) library that allows jDriver for Oracle to make calls into the non-Java Oracle client libraries. If you look at the exception that is generated, you will see that your applet fails in java.lang.System.loadLibrary, because the security manager determined that you were attempting to load a local library and halted the applet.

You can, however, use the WebLogic JTS or Pool driver for JDBC connectivity in applets. When you use one of these WebLogic multitier JDBC drivers, you need one copy of WebLogic jDriver for Oracle (or any other two-tier JDBC driver) for the connection between the WebLogic Server and the DBMS.

Q. Why doesn't my browser applet connect to the database?

Problem: I'm using a WebLogic multitier driver in an applet as an interface to a DBMS. If I run the class using the Sun Appletviewer on my local machine, I have no problems. But when I try to run the applet in a Netscape browser, it will not connect.

A. If Appletviewer works and Netscape does not, it is an indication that you are violating a Netscape security restriction. In this case, the violation is that an applet cannot open a socket to a machine other than the one from which it loaded the applet. To solve this problem, you will have to serve your applet code from the same machine that hosts the DBMS.

In addition, the IP naming format you use in the applet CODEBASE and the constructor for the T3Client must match. That is, you can't use dot-notation in one place and a domain name in the other.

Q. Why does my applet work with Appletviewer, but not with a browser?

Problem: I tried to run two of the applets in the examples directory of the distribution. I installed the WebLogic classes on my local machine (NT server) and on another machine (a Windows 95 client). I am not using any browsers, just trying to run the applets with Appletviewer. The applets work fine when I run Appletviewer from the NT server, but do not work at all from the Windows 95 client.

A. There are two possible problems: Either the CODEBASE tag is not properly set in the applet HTML file, or the class files are not properly loaded on the HTTP server.

The applet works on the NT server because you installed the WebLogic distribution on your NT server. Even if the applet cannot successfully load the necessary classes from the HTTP server, it does find them in your local CLASSPATH. But when you try to run it from the Windows 95 client, the applet must load the classes over the wire from the HTTP server, and if you haven't installed them correctly, it will fail.

Q. What's causing ClassFormatErrors with my applet?

Problem: I downloaded your distribution and copied the classes to my HTTP server DocumentRoot. I created an applet that I ran successfully from my Netscape server. I placed it in the server directory /webz/ns-home/classes/applets/myapp.class and called it with the following:

     CODEBASE=http://myserver.com/webz/ns-home/classes
CODE=applets.myapp.class>

Then I set my attributes in the Administration Console to listen on port 7001, and I started the WebLogic Server on the HTTP machine so I could use my applet with WebLogic JDBC, like this:

          CODEBASE=t3://myserver.com:7001/webz/ns-home/classes
CODE=applets.myapp.class>

When I changed the CODEBASE tag to point to the WebLogic Server, I started getting ClassFormatErrors.

A. There are several problems with your setup. The most obvious have to do with your CODEBASE:

  1. The CODEBASE tag in your applet should point to your HTTP server, not to WebLogic Server.
  2. The directory path referenced in your CODEBASE tag is not an absolute directory path on the HTTP server; it is a configured path that originates from the HTTP Document Root. You are using the absolute path in your CODEBASE tag. If your class "myapp" is in the "applets" package, then the correct CODEBASE for your setup would be:
           CODEBASE=http://myserver.com/classes
CODE=applets.myapp.class>

In addition, if you are getting a ClassFormatError, it signals a problem with your HTTP server configuration. It could be that you haven't loaded the WebLogic or applet classes in the correct directory on the HTTP server, or you are specifying the CODEBASE or the CODE incorrectly in your APPLET tag.

Remember, too, that if you installed the WebLogic distribution on the machine from which you are running the applet, your applet will first look for the WebLogic classes in your local CLASSPATH, which may obscure the fact that you haven't properly installed the classes for serving from the HTTP server. To test your HTTP configuration properly, you need to temporarily rename the WebLogic classes in your local CLASSPATH or try your applet from another machine.

Java Fundamental Questions

Q. Can you help me debug my program?

A. If the problem you are having is not directly related to our software, we suggest that you use a Java development tool that helps you with debugging, and that you invest in some books or training to help you learn Java. There are many ways to build debugging into your program, and getting good training in Java programming is a good start to understanding how to do this.

Q. Where can I get help learning Java?

A. There are a lot of books and online references to Java. A good starting place is at the JavaSoft website documentation index, which has links to white papers and the Java Tutorial. You can find books on Java at any of the major online book shopping sites.

Q. Where do I get the JDK?

A. WebLogic 6.1 bundles JDK131. See our Platform support page for information about specific JDKs that we have tested and certified for use with WebLogic software.

Once you determine which version of the JDK you will be using, go to the JavaSoft website. Many platform vendors provide an optimized version of the JDK for their computers.

Q. How do I set up my CLASSPATH?

A. Setting up your CLASSPATH correctly depends on what you are trying to do. The most common tasks are described below:

* Starting WebLogic Server. See Setting the Classpath Option in the Starting and Stopping WebLogic Servers section of the Administration Guide. In addition, your WebLogic distribution includes shell scripts that you can use to start the server. These scripts, which are located in the domain directories under the config directory of your WebLogic Server distribution, automatically set up the CLASSPATH variable in the shell before starting the server.

* Compiling Application Classes or Using WebLogic Server Utilities. See Setting the Classpath for Compiling in the Developing WebLogic Server Components section of Developing WebLogic Server Applications.

* Working With WebLogic Server Code Examples. See the WebLogic Server Examples Guide located at samples/examples/examples.html in your WebLogic Server distribution.

Q. Why won't the examples work?

A. Usually problems with examples are related to your environment. Here are some troubleshooting hints:

1. If you are using a database, make sure you have run the utility utils.dbping to verify that your JDBC driver is correctly installed and configured.

2. Run the setEnv script to make sure your CLASSPATH is correctly set in the shell or DOS window in which you are running the examples. For more information, see Setting your development environment.

3. Check the instructions for the examples to make sure you have changed any user-specific variables in the code before compiling.

4. Verify that you are compiling with the -d option to direct the class files into the proper directory, as defined in the example instructions.

If the example is an applet, check the CODE and CODEBASE, and make sure WebLogic Server is running.

Q. Where can I get help with Java error messages?

A. Many questions we receive at BEA are related to generic Java error messages and are not specific to WebLogic Server. Here are some links that contain helpful information about Java error messages.

This forum includes Questions and Answers on a wide variety of Java topics, including error messages. Use the Search box for fast results. For example, type "classpath error" in the Search box.

Compiler Error Messages

An extensive list of compiler error messages, including the infamous NoClassDefFoundError.

Sun's Java APIs. Check the Java API to see if there is an exception description for the class you are using.

Q. Why did a client-server message generate a StackOverflowException?

A. If you are sending a particularly large data structure using java.io.Serialization, you may exceed the per-thread size limit for either the Java or native stack. You can increase the stack size by using the following command line options:

-ss Stacksize to increase the native stack size or

-oss Stacksize to increase the Java stack size,

where Stacksize is expressed as an integer followed by "k" or "m" for kbytes or mbytes. For example,

$java -ss156k (native)

$java -oss600k (Java)

The default native stack size is 128k, with a minimum value of 1000 bytes. The default java stack size is 400k, with a minimum value of 1000 bytes.

Q. Will a JIT make my Java application run faster?

A. A Just-In-Time compiler will make some Java applications run faster. A JIT works by storing generated machine code in memory and reusing it when possible. For example, if you execute the same operation 1000 times in a loop, a JIT will improve performance of this operation since the code will only be generated once. Applications with a lot of native methods will not see as much performance improvement as pure-Java applications.

If you use a JIT, you may want to turn off the JIT during debugging to facilitate stacktracing. If you are doing performance testing with a JIT, make sure that you execute the same test several times in the same invocation and then throw away the first result to get an idea of how long the transaction will take when your application is running in a steady state. The first time the code is executed, your test will take longer (the "code generation hit").

Q. Can I redistribute the JDK that is bundled with WebLogic Server?

A. BEA Systems has the non-exclusive right to grant a third party, such as an independent software vendor (ISV), the right to redistribute the JDK that is bundled with WebLogic Server without any modifications of any kind. The following are caveats to this general statement:

* The ISV cannot remove or alter any proprietary legends or notices contained in the JDK. The ISV shall not decompile, disassemble, decrypt, extract, or otherwise reverse engineer or modify the JDK. The JDK may not be leased or assigned in whole or in part.

* The ISV must enter into a signed agreement with its distributors on terms substantially similar to those contained here in this redistribution policy explanation.

* The ISV requires an end user license agreement with the product within which it embeds WebLogic Server.

* The embedding of the JDK in ISV products does not include maintenance and support of the JDK by the JDK Provider. BEA Systems shall be solely responsible for providing maintenance and support for its ISVs and distributors. The ISV shall be solely responsible for providing maintenance and support for the end users of its products.

* If an ISV wants to ship a JDK that is different from the JDK that BEA ships with WebLogic Server, that ISV needs to get those bundling rights directly from Sun or HP. For example:

Assume that BEA ships WebLogic Server 6.0 with JDK 1.3 only, that BEA ships WebLogic Server 5.1 with JDK 1.1 only, and that an ISV wants to ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV. Unless BEA, for BEA business reasons, elects to make WebLogic Server 6.0 with JDK 1.1 generally available, the ISV couldn't ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV under BEA's agreement with that ISV or under BEA's agreement with Sun. The ISV could, however, obtain its own binary distribution agreement for the JDK from Sun and under that agreement bundle JDK 1.1 with its value added software solution consisting of the ISV applications and WebLogic Server 6.0 integrated