JBuilder5 + WebLogic 6.1sp1 Entity Bean

zhaozj2021-02-11  186

JBuilder5 WebLogic 6.1sp1 Entity Bean

This article assumes that the user has installed JBuilder5 and BAS4.5 correctly.

Install WebLogic

This example is WebLogic 6.1sp1, which is installed by default. The installation directory is set to 12345678.

Open JBuilder, select Enterprise Setup under the Tools menu, switch to the Application Server panel to select WebLogic Installation Directory to c: /bea/wlserver6.1, bea Home Directory is set to C: / BEA, then click OK. Click Default Project Properties to select the Servers panel, select the Servers panel, click on the Application Server - "....", Double-click the WebLogic Application Server 6.0 in the Application Server Selection Server 6.0 Modify VM Parameters as:

-ms64m -mx64m -djava.library.path = c: /bea/wlserver6.1/bin -dbea.home = C: / bea

-Dweblogic.domain = mydomain -dweblogic.name = MyServer

-Djava.security.policy == c: /bea/wlserver6.1/lib/weblogic.policy -classpath c: /bea/wlserver6.1/lib/weblogic_sp.jar; c: /bea/wlserver6.1/lib/ WebLogic.jar;

-Dweblogic.management.password = 12345678

Point OK, close the JBuilder. WebLogic configuration is complete.

Entity Bean

l Constructing a table in the test database

First create a table used to test, and the database name TEST Table Test We set two fields:

Name Vrachar (15) does not allow empty primary key addr varchar (50) allows empty

l Create a connection pool in WebLogic

1. Open the Start Default Server in the Start menu, and enter the password "12345678" to start WebLogic.

2. Start "Start Default Console", enter the username "system" password "12345678" to enter the console, find the "JDBC" item in the left menu, open him, you will find that there is a submenu to "Connection Pools", right Hit this item, then select "Configure a new JDBC Connection Pool ..." configuration connection pool

The property is as follows

Name MyDB URL JDBC: Sybase: TDS: 172.16.4.200: 5000 / TEST / 172.16.4.200 is the database server address, TEST is the database name /

Driver classname com.sybase.jdbc2.jdbc.sybdriver

Properties (key = value): user = sa

Aclname

Password

Click the CREAT button after completion.

3. Click the Targets tab, select MyServer, move it into the Chosen item, click Apply

4. Turn off the console and WebLogic service. The connection pool is already built.

l coding

1. Open JBuilder, create a newly named Hello project, and add WebLogic 6.0.2 in Required Libraries. Newly built an EMPTY EJB Group called HelloWorld.

3. Create a new Enterpris JavaBean, select the HelloWorld group, click Next. Package Select Hello, class name to "fistbean", Options Select Container Managed Persistence EJB 1.1 Entity Bean and click Next. Click Finish.

4. A total of 3 files under the project is

First.java

Package hello;

Import java.rmi. *;

Import javax.ejb. *;

/ **

* Title:

* DESCRIPTION:

* Copyright:

* Company:

* @Author Zhao Xinpeng

* @version 1.0

* /

Public interface first extends ejbobject {

Public java.lang.string getaddr () throws remoteException;

Public java.lang.string getname () throws remoteexception;

Public void setaddr (java.lang.string addr) throws RemoteException;

Public void setname (java.lang.string name) throws RemoteException;

}

FistBean.java

Package hello;

Import java.rmi. *;

Import javax.ejb. *;

/ **

* Title:

* DESCRIPTION:

* Copyright:

* Company:

* @Author Zhao Xinpeng

* @version 1.0

* /

Public class firstbean imports entitybean {

EntityContext EntityContext;

Public String Name;

Public String Addr;

Public String Ejbcreate (String Name, String Addr) throws createException, RemoteException {

SetName (Name);

SetAddr (AddR);

Return NULL;

}

Public string ejbcreate (String name) throws createException, RemoteException {

Return EJBCREATE (Name, NULL);

}

Public void ejbpostcreate (String name, string addr) throws createException, RemoteException {

}

Public void ejbpostcreate (String name) throws createException, RemoteException {

}

Public void ejbload () throws remoteexception {

}

Public void ejbstore () throws remoteException {

}

Public void ejbremove () throws removeexception, remoteexception {

}

Public void ejbactivate () throws remoteexception {}

Public void ejbpassivate () throws remoteexception {

}

Public void setentityContext (entityContext entityContext) throws remoteException {

THIS.EntityContext = EntityContext;

}

Public void unsentityContext () throws remoteException {

EntityContext = NULL;

}

Public String getAddr () {

Return addr;

}

Public void setaddr (string addr) {

THIS.ADDR = Addr;

}

Public string getname () {

Return Name;

}

Public void setname (String name) {

THIS.NAME = Name;

}

}

FIRSTHOME.JAVA

Package hello;

Import java.rmi. *;

Import javax.ejb. *;

/ **

* Title:

* DESCRIPTION:

* Copyright:

* Company:

* @Author Zhao Xinpeng

* @version 1.0

* /

Public interface firsthome extends ejbhome {

Public first create (String name) Throws createException, RemoteException;

Public First Create (String Name, String Addr) Throws CreateException, RemoteException;

Public Fist FindbyPrimaryKey (String PrimaryKey) throws RemoteException, FINDEREXCEPTION

}

5. Click HelloWorld.ejbgrp in the left menu, then double-click First, the first-page, click the Resource References tab below, click the Add button on the panel, enter "HelloDB" point OK in the input dialog box. Select Type to java.sql.datasource. Select HelloDB and enter MYDB in the JNDI Name box below.

6. Then click on the label Persistence, TABLE (s), and the contents of the container management table are as follows.

CMP

ISPK

FIELD TYPE

Column Name (s)

Column Type

Check Name Name Varchar (15)

Select Addr ADDR VARCHAR (50)

7. Right-click on the JDBC Datasources under EJB Deployment Descriptor to create a new data source named mydb, configured as follows:

JNDI Name MyDB

URL JDBC: Sybase: TDS: OLAP: 5000 / TEST

User Name Sa

Password

Driver class name com.sybase.jdbc2.jdbc.sybdriver

Configuration Finish Click "Test Connection", if it is correct

Attempting to connect to Database ...

Connection succeed.

If you display the following information

Attempting to Connect to Database ... driver not on classpath.

Add the driver to the classpath using The set classpath command.

Then indicate that the JDBC driver of the database is not in the classpath, adds the database's driver to the project's Required Libraries.

8. Click EJB Deployment Descriptor, then click EJB DD SOURCE in the right window, then select WebLogic-Cmp-Rdbms-Jar.xml to find Modified to MYDB .

9. Right-click FirstHome.java to select Properties, then select Build Panel ---> Visibroker Select the generate IIOP point OK under Java2iiop Seting

10. After saving, press CTRL F9 to compile, there should be no problem.

11. New Test EJB Client all uses the default settings.

12. Remove the main method to find fisttestclient1 client = new fistteclient1 ();

Then add the following code:

First ff = client.create ("testname", "testaddr");

Try {

System.out.println (ff.getname ());

System.out.println (ff.getaddr ());

}

Catch (java.rmi.remoteexception ex) {

EX.PrintStackTrace ();

}

Then, save compilation.

13. Right-click HelloWorld.ejbgrp, choose RUN, then select Deploy Options for "HelloWorld.jar" àDeploy

14. Open http://127.0.0.1:7001/console username password after completion, SYSTEM and 12345678 Open EJB in the left menu of the console, then select Targets to turn MyServer in the window. CHOSEN.

15. Go back to jBuilder to stop the running server, then re-right hit helloworld.ejbgrp, select RUN.

16. Right-click on the fisttestclient1.java point run, such as displaying the information below, is successful

Initializing Bean Access.

- succeeded initializing bean access.

. - Execution Time: 1663 MS.

- Calling Create (Testname, TestAddr)

- succeeded: Create (Testname, TestAddr)

- Execution Time: 200 ms.

- Return Value from Create (Testname, Testaddr): WebLogic.rmi.Cluster.EntityRemoteref@10F - JVMID: '190 ...

Testname

TestAddr

转载请注明原文地址:https://www.9cbs.com/read-5176.html

New Post(0)