Before doing this document, please ensure the following points first.
(1) Preparing
1 First JB and WebLogic have guaranteed integration, my version is JB7 WebLogic 6.12 has the correct data source, it is best to have successfully configured the connection pool in your WebLogic. 3 It is best to have some experience in jdbc in jbuilder before. These two steps can be found in the document http://www.9cbs.net/develop/Article/15/15250.shtm
(2) The establishment of the project 1 first build a project called cmptest, choose the path where your project is located, do not choose, directly finished2 now new EJB2.0 Designer, if your CMP cannot be established, please ensure that you have prepared work. There is also a problem that the work of this project is also Tomcat4, modifying Server in the engineering property is WebLogic. 3 Popping a box, point new, named CMP1 and then OK, then OK
(3) Database establishment and CMP establishment 1 CMP is established, a Database appears in the lower left corner, right-click, Import from schema database. You can choose DRIVER, URL, User, Password, JDNINAME and other parameters. 2 If your Driver is red, you need to do the following. Tools-> Enterprise Setup, click Add on the Database DRIVERS page, click New in the pop-up dialog, then join your Driver, OK. 3 Next, the first step, if each parameter fills in correct, then you will see a wait process, under Database, you can see the name of the JDNI you filled in. Expand you can see that all the tables of the database are guided. 4 Expand the table you need to create a CMP (my table is ahu), right click Create CMP 2.0 EntityBean, the first time you choose a table with only one primary key, so the system will not generate a primary key with you. This way you should see three files Ahuser.java AhuserHome.java AhuserBean.java, which is your bean class, remote interface, and home interface. So far, your CMP has been released, simple.
5 Waiting, if you release it now, the system will tell you that DataSource is not registered, so you have to have a DS that is the same name as the current Datasource in WebLogic.
(4) Establishing a stateless sessionBean to call your CMP1 on the panel to right-click Create EJB-> session bean, in the first line, the name of the sessionbean, my name is beanQueryah2 right-click Add Methord, write your method name Intecaces change to Remote Call 3 Return Type Choose Java.lang.String4 Input Parameters Enter java.lang.string Mobile, this time, remote methods are fine. 5 Right-click this bean, view bean source. View code can see this method you build and the parameters, I am like this.
Public Java.lang.String Queryah (java.lang.string Mobile) {Return Null;}
In this method, we will generate references to CMP, modify the method as follows. Among them, AhuserHome, Ahuser is the CMP BEAN class and HOME interface I have generated above. Public Java.lang.String Queryah (Java.lang.String Mobile) {string sreturn = "none"; try {ahuserhome ahh = (ahuserHome) () ("java: / comp / enc / cmp1") ); Ahuser ahuser = ahh.findbyprimaryKey (mobile); sreturn = ahuser.getlogintime ();} catch (exception ex) {ex.printStackTrace (); sreturn = "error";} returnif
Everyone pays attention to this sentence ahuserhome ahh = (ahuserhome) () (). Lookup ("Java: / Comp / ENV / CMP1));
Due to the same container, calling CMP does not require RMI remote calls. With a way to write environment variables, the above words must be successful, you must do the following. Select your bean, choose the right EJB LOCAL REFERENCES, ADD, and fill in the name CMP1, then generate a line, select the islink to select Ahuser, Type selection Entity.
In this way, you can call your EJB locally through this environment variable.
Of course, everyone can modify these two sentences according to their own database to return different values. Ahuser Ahuser = ahh.FindByPrimaryKey (Mobile); sreturn = ahuser.getlogintime ();
(5) The client's establishment 1 In JB, a new EJB Client Test, the default below 4 check boxes are three, OK2 finds the main method is the public static void main (String [] args) { BeanQueryAHTestClient1 client = new BeanQueryAHTestClient1 ();. // 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 studes. You can also just use the //client object to call the remote interface wrappers.
3 modified public static void main (String [] args) {BeanQueryAHTestClient1 client = new BeanQueryAHTestClient1 (); // 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.print ("13956261950"); System.out.Print (Client.Queryah ("13955177766)); System.out.print (Client.Queryah (" 13956395757)); system.out. Print (Client.Queryah ("13956536656));} (6) After running 1 compile, generate * .jar files, start WebLogic, deploy * .jar to 2 Run the client, print in the command console - Initializing Bean Access.
- succeeded initializing bean access.
- Execution Time: 2274 ms.
- Calling Create ()
- succeeded: CREATE ()
- Execution Time: 70 ms.
- Return Value from Create (): ClusterableRemoteRef (172.16.58.178 [172.16.58.178]) / 270.
- Calling Queryah (13956261950)
- succeeded: Queryah (13956261950)
- Execution Time: 170 ms.
- Return Value from queryryah (13956261950): 020924122246.
020924122246-- Calling queryryah (13955177766)
- succeeded: Queryah (13955177766)
- Execution Time: 10 ms.
- Return Value from Queryah (13955177766): 020914085733.
020914085733 - Calling Queryah (13956395757)
- succeeded: Queryah (13956395757)
- Execution Time: 30 ms.
- Return Value from Queryah (13956395757): 020913163627.
020913163627 - Calling Queryah (13956536656)
- succeeded: Queryah (13956536656)
- Execution Time: 10 ms.
- Return Value from queryah (13956536656): 020913162439.0209131624393 View your weblogic page
EJBName Idle Beans Count Beans In Use Count Waiter Total Count Timeout Total Count Cached Beans Current Count Cache Access Count Cache Hit Count Activation Count Passivation Count Lock Entries Current Count Lock Manager Access Count Waiter Total Count Timeout Total Count AhUser 1 4 0 0 4 16 12 4 0 0 0 0 0
Some information of this entity bean can be seen.
All progents authors have tried it, the environment JB7 WebLogic 6.1, please contact jiangyz@hoten.com, please explain it. Thank you
Send (how to achieve JSP JavaBean SessionBean CMP)