Practical JBUILDER7 + WebLogic7 (continued session bean)

zhaozj2021-02-08  224

Battle JBUILDER7 WebLogic7 Access MS SQL Server2000 (1)

Liu Xiaowei: Liuxiaowei2000@sina.com

For the first time, I hope everyone will hold a lot. This article is completely written according to my personal experience. If there is any mistake, please ask you to correct!

JBuilder7 WebLogic7 configuration

Suppose JBuilder7 and WebLogic7 are installed, the operating system is: Windows2000 Server (SP2), the database is: SQLServer2000 (SP2).

JBUILDER7 configuration:

1. Modify environment variables TEMP and TMP for directorys without spaces such as: E: / WinNT / TEMP

2. Start JBuilder7, choose: Tools-> Configure Servers

3. Select the WebLogic Application Server 6.x on the left, select the enable server on the right.

4. Set General-> Home Directory to WebLogic7 Home Directory, such as: E: / BEA / WebLogic700 / Server, normal JBuilder7 will automatically add other items to you.

5. Set the Custom-> JDK Installation Directory as the JDK installation directory, such as: E: / BEA / JDK131_02

6. Set the Custom-> Bea Home Directory to WebLogic7 home director, such as: E: / BEA

7. Set Custom-> Domain Directory as your domain directory, such as: E: / bea / user_projects / mydomain

8. Add User Name, Password, Domain Name, Server Name, click OK to exit.

9. Select: Tools-> Enterprise Setup, click New on the CORBA page, follow the table to fill in the appropriate information:

Name for this configuration = Wellogic 7.0

Path for orb Tools = E: / bea / WebLogic700 / Server

Library for processing = WebLogic 6.x Deploy

IDL Compiler Command = idlj.exe

Commnad option for output directory = E: / corbaoutput (any directory, do not have spaces)

Click OK to exit.

10. Choose Project-> Default Project Properties

WEBLOGIC 6.X Client and WebLogic 6.x deploy in the Required Libraries in the PATH page are not, please check if the above steps are correct.

11. Select Server page, click Single Services for All Service in Project

Select WebLogic Application Server 6.x in the drop-down list, but strike OK exit, configure it.

WebLogic7 configuration:

1. Start WebLogic7

2. Open IE6 and enter: http: // localhost: 7001 / console3. Enter your username and password

4. Select Services-> JDBC-> Connection Pools in the directory tree on the left, click the Configure a new JDBC Connection Pool on the right. You enter the following information:

Configuration-> General Page:

Name = SQL Server Connection Pool

URL = JDBC: WebLogic: MSSQLSERVER4: Northwind @ localhost

Driver classname = WebLogic.jdbc.msqlserVer4.driver

Properties: User = SA

Password = "" <- SA password

Click Create to establish a connection pool.

Targets-> Server Page:

Move your MyServer to the list of the right, but click Apply

5. Select Services-> JDBC-> Data Sources-> JDBC-> Data Sources-> JDBC-> Data Source, click on the CONFIGURE A NEW JDBC Connection Pool on the right. Enter the following information:

Configuration-> General Page:

Name = SQLSERVER TX DATA SOURCE

JNDI Name = SQLServer

Pool Name = SQL Server Connection Pool

Select Emulate TWO-PHASE COMMIT for Non-Xa Driver and Row Prefetch Enabled

Click Create to establish a data source.

Targets-> Server Page:

Move myServer to the list of the right, but click Apply, the configuration is complete.

Practical 1: Connect SQLServer2000

1. Open JBuilder7 Select File-> New Project

Enter SQLSERVERDEMO in the Name column, enter the storage path in the Directory column (do not have spaces), other unchanged, click Finish.

2. Select File-> New, select General-> Application, click OK.

The first step, the second step and third steps do not have to be changed, directly finish.

3. Go back to the JBuilder7 integrated development environment, click the Designer page design form on the right, put a JScrollPane and Jtextarea and three buttons in the form, double-click the first button to enter the following code:

Try

{

Class.Forname ("WebLogic.jdbc.mssqlserVer4.driver");

Connection con = DriverManager.getConnection ("JDBC: WebLogic: MSSQLServer4: Northwind @ localhost", "sa", ""); // is based on your SQLServer account.

Statement ST = con.createstatement ();

ResultSet Res = St.executeQuery ("Select * from Employees);

String line = "";

While (res.next ())

LINE = line res. maxString ("Title") "/ n";

Jtextarea1.settext (line);

C. close ();

}

Catch (Exception EX)

{

Jtextarea1.settext ("Error:" ex.getMessage ());

}

Double-click the second button to enter the following code

Hashtable ht = new hashtable ();

HT.PUT (Context.Initial_Context_Factory, "WebLogic.jndi.wlinitialContextFactory";

HT.PUT (Context.Provider_URL, "T3: // localhost: 7001");

Try

{

Context CTX = New InitialContext (HT);

DataSource DS = (Datasource) CTX.lookup ("SQLServer");

Connection con = ds.getConnection ("System", "12345678"); // This is WebLogic7

Domain users and passwords

Statement ST = con.createstatement ();

ResultSet Res = St.executeQuery ("Select * from Employees);

String line = "";

While (res.next ())

LINE = line res. maxString ("notes") "/ n";

Jtextarea1.settext (line);

C. close ();

}

Catch (Exception EX)

{

Jtextarea1.settext ("Error:" ex.getMessage ());

}

Run WebLogic7, run the program Click the first button to connect SQL Server directly using JDBC and get data, click the second button to connect SQL Server with DataSource and get data.

Practical 2: session bean

Establish a simple bean:

1. Turn off all works: file-> Close Projects

2. Select File-> New Project

Enter Hellodemo in the Name column, enter the storage path in the Directory column (do not have spaces), other unchanged, click Finish.

3. Select File-> New-> Enterprise-> EJB 2.0 Designer Click OK.

In the pop-up dialog box, click New to create a moudle, enter the Hellomoudle in Name, click OK to close the current dialog, click OK to close the dialog.

4. Click Right click in the workspace on the right: Create EJB-> session bean, change Bean Name to Hellobean

5. Right-click on the rectangle representing Hellobean, select Add-> Method to fill in:

Method name = Sayhello

Return Type = java.lang.string

INPUT parameter does not add

Interface = Remote

6. Right-click on the rectangle of Hellobean, select View Bean Source

Fill in Sayhello as follows:

Public Java.lang.String SayHello ()

{

/ ** @ Todo Complete this method * /

Return New String ("Hello World");

}

7. Press F9 to run, select the RUN page in the pop-up dialog box, click New, fill in Server Runtime Configuration at Configure Name, then select Run-> Server, click OK to close the current dialog box, click OK to start compiling and run . Right-click Hellomodule selection after running, right-click Hellomodule Select: Deploy Options for "Hellomodule.jar" -> Deploy to publish bean.

Establish a client:

1. Select File-> New-> Enterprise-> EJB Test Client Click OK.

Select Genrate Method for Test Remote Interface Calls with default arguments Click OK.

2. Fill in main ():

Public static void main (string [] args)

{

HellobeantestClient1 Client = New HellobeantestClient1 ();

// Use the client object to call one of the home interface wrappers

// Above, to create a remote interface reference to the bean.

// if the return value is of the remote interface type, you can use it

// TO Access The Remote Interface Methods. You can also Just Use the

// Client Object to Call The Remote Interface Wrappers.

Client.create ();

System.out.println (Client.Sayhello ());

}

select

Run

-

> Run "HellobeantestClient1.java" Using Defaults

run.

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

New Post(0)