WebLogic 6.1 + JBuilder 9 -----> EJB

xiaoxiao2021-03-06  76

The environment is set to: WebLogic 6.1 JBuilder 9; Data Table is TMP_EMP, and this table is required to use EJB. Fields are: SQL> DESC TMP_EMP; Name Type Nullable Default Comments -------- ------------------------- ---------------------------------- ID VARCHAR2 (10) Staff id name varchar2 (20) Y staff name Job VARCHAR2 (20) Y staff's work name HIREDATE DATE Y staff in-job time SAL Number (7, 2) Y staff salary comm Varchar2 (20) Y Note DeptID VARCHAR2 (10) Y staff Service department ID; and TMP_DEPT table ID association

Preparatory: Encoding Basic Pattern: The package is all lowercase letters, such as the method of combining the EJBSAMPLE.Session class name, and the first letter uppercase, such as the Method of EmployeeAction variable name, and the first letters, such as the Strname module Level variables plus underscores, such as _strname database settings: Install Oracle's client to ensure that the database server has been properly established.

JBUILDER9 setting: You can refer to the previous article. Important: Oracle's library file setting; "Enterprise Setup" setting

WebLogic setting:

Start WebLogic

Open the console: http: // localhost: 7001 / console

From JDBC's Connection Pools, "Configure a new jdbc connection pool", parameters can refer to the following:

** Name: EJBDEMO (Description: This can be arbitrarily taken) ** URL: JDBC: Oracle: Thin: @ 172.16.3.100: 1521: DEV3 (Description: This URL is the URL of the JDBC connection, the format can refer to the JDBC document; DEV3 is a SID on the database server 172.16.3.100 ** driver classname: Oracle.jdbc.driver.racledriver ** Properties: user = PMPassword = PMDLL = OCIJDBC8PROTOCOL = Thin (Description: Username and Password replacement) ** Initial Capacity3 ** maximum capacity10 (Note: Don't forget "Targets" inside "Available" Apply to "Chosen") Configure a "tx data source": ** name: ejbds ** jndi name: EJBDS (Description: This is when the EJB is designed, the data source name to be specified) ** pool name: ejbdemo (Description: This is the name "EJB Module" in the JBuilder: It is recommended to save the .jar file Location can be placed in the Applications directory of WebLogic: c: /bea/wlserver6.1/config/mydomain/applications After building an empty module, first configure its "DataSources". Right click "Datasource" and select "Import Schema from Database".

First, "DRIVER" is "Oracle.jdbc.driver.OracleDriver", then the URL fills in "JDBC: Oracle: Thin: @ 172.16.3.100: 1521: dev3", "username" and "Password" fill in the correct (I The "PM", "PM"), "JNDI Name" is filled in "JNDI Name", and after the JBuilder automatically begins "Importing Schema" in the database. If such actions do not have this action, the previous database is not correct, check it again. Designing entity beans in JBuilder's EJB Designer: In the data sheet you have to operate from the JBuilder, find the TMP_EMP table we want to operate. Right click on it, select "CREAT CMP 2.0 Entity Bean", and JBuilder will automatically generate entity beans according to the structure of the table. If you are not satisfied with the parameters generated by JBuilder, you can modify it. I changed as follows:

** bean name: EBNemPloyee (Description: After the bean name, Abstract Schema Name will automatically change the same name) ** interfaces: local ** classes and packages: ejbsample.employee.Entity (Description: a) Package Capture b) On JBuilder's Classes and Packages define pages, you only need to enter default package for ejbsample.employe.Entity, other item JBuilder will automatically fill it) ** Add 3 methods (of course, if you need to add methods, you can always to JBuilder the EJB designer which add): void setModel (EmployeeModel model) method (interface: local) EmployeeModel getModel () method (interface: local) ejbCreate (EmployeeModel model) method (interface: local home) (Description: EmployeeModel class It is now established in the EJB designer of JBuilder to design session bean: Right-click on JBuilder's EJB design container, select New Session Bean. The modified parameters are as follows: ** bean name: sbnemployee ** session type: stateless ** interface: remote ** class - default package: ejbsample.employee.Session ** Add the following method (Of course, if you need to add a method, you can always to JBuilder the EJB designer which add): EmployeeModel insert (EmployeeModel model) method (interfaces: remote) EmployeeModel update (EmployeeModel model) method (interfaces: remote) boolean del (String pk) methods (interfaces: remote) EmployeeModel findByPk ( String PK) Method (Interfaces) Boolean Delbatch (Interfaces: Remote) Java.util.ArrayList QueryBysql (String Strsql) Method (Description: We can see the use of the Employeemodel class It is everywhere. In fact, all pages displayed in Employeemodel, when dealing with the JSP page, it will play an important role.) Beginnely Employeemodel class: New Class, named Employeemodel, package Defined as EJBSAMPLE.EMPLOYEE, the base class is selected as java.io.serializable. The content is as follows: package ejbsample.employee;

Import java.io.serializable;

/ ** * Title: (No title) * Description: In general, the XXMODEL class can be seen as a package for all display elements for the JSP page. It will be a class that is mainly derived from the JSP page * Copyright: Copyright: Copyright (C) 2003 * Company: ebuilds * @Author Alex * @version 1.0 * / public class Employeemodel Implements Serializable {

private String _strID; // employee ID private String _strName; // Staff name private String _strJob; // staff working name of private java.sql.Date _dtHireDate; // staff entry time private double _dSal; // salaries by private String _strComm ; // Remark the private string _StrDeptID; // The department ID of the staff is associated with the ID_DEPT table

// Set the property, read the attribute to start public string getId () {return_strid;} public void setid (string in) {_strid = in;

Public string getName () {return_strname;} public void setname (string in) {_strname = in;

Public string getJob () {return_strjob;} public void setjob (string in) {_strjob = in;

Public java.sql.date gethiredate () {return_dthiredate;} public void designate (java.sql.date in) {_dthiredate = in;}

Public Double Getsal () {return_dsal;} public void setsal (double in) {_dsal = in;

Public string getcomm () {return _strcomm;} public void setcomm (string in) {_strcomm = in;

Public string getDeptid () {return _STRDEPTID;} public void setdeptid (String in) {_STRDEPTID = in;} // Setting attribute, reading attribute ends

Public void setmodel (Employeemodel IN) {_strid = in.getiD (); _StrName = in.GetName (); _STRJOB = in.GetJob (); _dthidate = in.GethiRedate (); _dsal = in.getsal (); _STRCOMM = In.getComm (); _STRDEPTID = in.GetDeptid ();} public employeemodel () {} public static void main (String [] args) {Employeemodel Employeemodel1 = new Employeemodel ()

} Write a public class of EJB: EJBCOMMON.JAVA. Very important code!

Package ejbsample;

/ ** * Title: (no title) * Description: This is a common class that needs to be used when writing EJB, such as the JNDI name, take the home interface. When there are many EJBs, this class is very necessary * Copyright: Copyright (C) 2003 * Company: ebuilds * @Author Alex * @version 1.0 * / import java.util. *; Import javax. naming *;. import javax.ejb *;. import javax.rmi.PortableRemoteObject; import javax.naming.InitialContext; import javax.naming.NamingException; import weblogic.jndi.Environment; import javax.sql *;. import java.sql . *;

Public class ejbcommon {

// This is stored all JNDI names. If the JNDi name is much, it is recommended to put them separately in a file. // Description: JNDI name is here: JB "Project Content", double-click "EBNEMPLOYEE", you can see "local home jndi name", that is. Public static final string e_employee_jndi = "ebnemployee"; public static final string s_employee_jndi = "sbnemployee"; public static final string DataSource_jndi = "EJBDS";

// The following is a function of the HOME interface-related function private static context context = NULL;

/ * ** made InitialContext, take home interface for later * @return * @throws NamingException * / protected static Context getInitialContext () throws NamingException {String user = null; String password = null; Properties properties = null; try {properties = new Properties (); properties.put (Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); if (user = null!) {properties.put (Context.SECURITY_PRINCIPAL, user); properties.put (Context.SECURITY_CREDENTIALS, Password == NULL? "": password);} return new initialcontext (proties);} catch (namingexception e) {throw e;}} / ** * is used to obtain a remote home interface. In general, the interface of the session bean is remote (not local), so the HOME interface to get the session bean should be used to use this function * @Param lookupname * @Param HomeClass * @return * / public static object GetRemoteejbhome (String Lookupname, Class homeclass) throws namingexception {try {== null) {context = getInitialContext ();

Object home = portableremoteObject.narrow (CONTEXT.LOOKUP (Lookupname), HomeClass;

Return home;} catch (namingexception ne) {// throw new ejbexception (ne.getMessage ()); throw ne;}}

/ ** * is used to obtain a local home interface. In general, the interface of the entity bean is local (LOCAL), so the HOME interface for obtaining the entity bean is used to use this function. * @Param lookupName * @return * / public static Object getLocalEJBHome (String lookupName) throws NamingException {try {if (context == null) {context = getInitialContext ();} Object home = context.lookup (lookupName); return home; } catch (namingexception ne) {// throw new ejbexception (ne.getMessage ()); throw ne;}} // below is about the operation of the database. An important thing, after getConnection (), remember to release the connection!

/ ** * taken from inside a defined datasource connection * @return * / public static Connection getConnection () throws NamingException, SQLException {Connection con = null; try {if (context == null) {context = getInitialContext (); } DataSource datasource = (DataSource) context.lookup (DATASOURCE_JNDI); con = datasource.getConnection ();} catch (NamingException ex) {throw ex;} catch (SQLException ex) {throw ex;} return con;}

/ ** * This is a remote version taken. But it seems that you don't need to use it. * @Return * / public static Connection getConnection_remote () throws NamingException, SQLException {try {if (context == null) {context = getInitialContext ();} DataSource ds = (DataSource) PortableRemoteObject.narrow (context.lookup (DATASOURCE_JNDI), DataSource.class; return ds.getConnection ();} catch (namingexception ne) {// throw new ejbexception (ne.getMessage ()); throw ne;} catch (sqlexception e) {// throw new EJBEXCEPTION (E. GetMessage ()); throw e;}} / ** * role: Enter strmsg into the C: / strlogfile file in HTML format * will output a statement similar to this: * [2003-April-29 04:44 : 03] is a debug file: vwDetail.jsp is set to start debugging function :( projectID) debug description: projectID made for ERPPM200212110000000658310000E8E7FF69 * * Added by daihua 2003-4-29 11:16 * @param strMsg * / public static void logOneLineToFile String strlogfile, String strDebu GFileName, String strDebugFuncName, String strdebugmsg) {// If you do not need debug output, return / * if (! debuggingon) return; * / java.io.file fd = new java.io.file ("C: // Debug "); if (! fd.exists ()) {fd.mkdirs ();

// Automatically generate debug file names based on the current date, such as: C: / 20030506Debug.html / * SimpleDateFormat SDFF = New SimpleDateFormat ("YYYYMMDD"); string strlogfilename = "c: // debug //" SDFFFFORMAT (New Date ()) "Debug.html"; * /

String strlogfilename = "c: // debug //" strlogfile; // is also specified by the program to specify the file name java.text.SIMpleDateFormat BartdateFormat = new java.text.SIMPLEDATEFORMAT ("YYYY-MMMM-DD HH: mm: SS "); Java.util.date date = new java.util.date (); java.io.filewriter out = null; try {java.io.file f = new java.io.file (strlogfilename); if (! F.EXISTS ()) {f.createNewFile ();} // out = new randomaccessfile (f, "rw"); out = new java.io.filewriter (strlogfilename, true); // to be ready for append / /out.seek (out.Length ()); string str1 = "

" [" bartdateformat.format (date) "] is debugged file: "; string str2 =" strDebugfilename "; string Str3 = " Trial function: strDebugfuncname " "; string S Tr4 = " debug description:
/ r / n"; strdebugmsg = "" strDebugmsg " / r / n "; strDebugmsg = str1 str2 str3 str4 strDebugmsg; //out.writechars (" [" bartdateformat.format (date) "] " strmsg " / r / n ") ;

Out.write (strDebugmsg);} catch (exception e) {E.PrintStackTrace ();} finally {try {if (out! = null) Out.close ();} catch (exception ex) {EX.PrintStackTrace () }}} Public ejbcommon () {} public static void main (String [] args) {ejbcommon ejbcommon1 = new ejbcommon ();

} Editing Complete Entity Bean

Open EBNEMPLOYEE, EBNemPloyeeHome, EBNemPloyeebean, first imported: import ejbsample.employee.employeemodel; then edit EBNEMPLOYEEBEAN, complete the function of the EJB designer

Void SetModel Model function:

Public void setmodel (Employeemodel model) {this. setid ()); this.setName (); this.setJob (MODEL.GETJOB ()); this.SethiRedate () This.Setsal (Model.getsal ()); this.setcomm (Model.getComm ()); this.SetDeptid ());} Employeemodel getModel () function

Public Employeemodel getModel () {Employeemodel Data = new Employeemodel (); data.setid ()); data.setname (this.getName ()); data.setJob (this.getjob ()); data.sethired ()); data.setsal (this.getsal ()); data.setcomm (this.getComm ()); data.setdeptid (this.GetDeptid ()); return data;} java.lang.string EJBCREATE (Employeemodel Model)

Public java.lang.string ejbcreate (Employeemodel model) throws createException {// Description: This function is very important. When you create an entity bean, EJBCREATE will automatically call, so if this function is not completed, the entity bean will not be assigned. SetModel; Return NULL;} Edit Finish Session Bean Sbnemployeebean.java, as follows Package Ejbsample.employee.Session;

import javax.ejb *;. import ejbsample.employee.EmployeeModel; import ejbsample.EjbCommon; import java.util.ArrayList; import ejbsample.employee.entity *;. import javax.naming.NamingException; import java.sql *;. import Java.rmi. *;

public class SbnEmployeeBean implements SessionBean {SessionContext sessionContext; public void ejbCreate () throws CreateException {/ ** @ todo Complete this method * /} public void ejbRemove () {/ ** @ todo Complete this method * /} public void ejbActivate () {/ ** @ todo Complete this method * /} public void ejbPassivate () {/ ** @ todo Complete this method * /} public void setSessionContext (sessionContext sessionContext) {this.sessionContext = sessionContext;} public EmployeeModel insert (EmployeeModel model ) throws CreateException, NamingException, RemoteException {try {// class obtained using EjbCommon home interface entity bean EbnEmployeeHome objHome = (EbnEmployeeHome) EjbCommon.getLocalEJBHome (EjbCommon.E_EMPLOYEE_JNDI); EbnEmployee objRemote = objHome.create (model); return model;} CATCH (CreateException E) {throw e;} catch (namingexception e) {throw E;

}

public EmployeeModel update (EmployeeModel model) throws FinderException, NamingException, RemoteException {try {// class obtained using EjbCommon home interface entity bean EbnEmployeeHome objHome = (EbnEmployeeHome) EjbCommon.getLocalEJBHome (EjbCommon.E_EMPLOYEE_JNDI); EbnEmployee objLocal = objHome.findByPrimaryKey (model .GetId ()); // call MODEL's acquisition, put the entity bean //objlocal.seTmodel (Model); // can't write. Specifically, I don't know. It seems that there is no reason. Objlocal.setname (Model.GetName ()); Objlocal.SetHiRedate; objlocal.setsal ()); Objlocal. SetComm (model.getCMM ()); Objlocal.SetDeptid (Model.GetDeptid ()); return model;} catch (FINDEREXCEPTION E) {throw e;} catch (namingexception e) {throw e;}}

public boolean del (String pk) throws RemoveException, FinderException, EJBException, NamingException, RemoteException {try {// class obtained using EjbCommon home interface entity bean EbnEmployeeHome objHome = (EbnEmployeeHome) EjbCommon.getLocalEJBHome (EjbCommon.E_EMPLOYEE_JNDI); EbnEmployee objLocal = objHome .findByPrimaryKey (pk); objLocal.remove (); return true;} catch (RemoveException e) {throw e;} catch (FinderException e) {throw e;} catch (EJBException e) {throw e;} catch (NamingException e ) {Throw e;}

}

public EmployeeModel findByPk (String pk) throws FinderException, NamingException, RemoteException {try {// class obtained using EjbCommon home interface entity bean EbnEmployeeHome objHome = (EbnEmployeeHome) EjbCommon.getLocalEJBHome (EjbCommon.E_EMPLOYEE_JNDI); EmployeeModel model = new EmployeeModel (); EbnEmployee objLocal = objHome.findByPrimaryKey (pk); model = objLocal.getModel (); return model;} catch (FinderException e) {throw e;} catch (NamingException e) {throw e;}} public boolean delBatch (String [] sid) throws NamingException, SQLException, RemoteException {String [] sID = null; sID = sid; String sql = "delete FROM tmp_emp WHERE ID = '"; // Note: statmachine is the table name connected with our work String id = new String (); connection conn = null; statement st = null; boolean b = false;

Try {conn = ejbcommon.getConnection (); conn.setautocommit (false); st = conn.createstatement (); for (int i = 1; i <= SID.LENGTH; i ) {id = SID [i-1] St.execute (SQL ID "");} conn.commit (); b = true; return b;} catch (namingexception e) {throw e;} catch (sqlexception e) {system.err.print ("Delbatch () function error"); try {conn.rollback ();} catch (sqlexception sqle) {throw SQLE;} throw e;} finally {try {st.close (); conn.close ();} Catch (SQLEXCEPTION E) {throw E;} // Return B; // Description: Do not in Finally Return, otherwise, the captured error will not be throw! ! ! }

public java.util.ArrayList queryBySql (String strSql) throws NamingException, SQLException, RemoteException {ArrayList arrayList = null; EmployeeModel item; Connection conn = null; Statement st = null; ResultSet rs = null; try {conn = EjbCommon.getConnection () ; st = conn.createStatement (); rs = st.executeQuery ( "SELECT * FROM tmp_emp WHERE" strSql); // of course, you can change the sql statement according your condition System.out.println ( "queryBySql function SQL = " " Select * from tmp_emp where " strsql); arraylist = new arraylist (); while (rs.next ()) {item = new Employeemodel (); // Read the value Item.setId from the database ( rs.getstring ("ID")); item.setname (Rs.getstring ("name")); item.setJob (rs.getstring ("job")); item.sethiRedate (Rs.Getdate ("HiRedate") ); Item.setsal (rs.getdouble ("sal"); item.s ETCOMM (RS.GetString ("Comm"); item.setDeptid (rs.getstring ("deptid");

ArrayList.Add (item);} IF (arraylist.size () <= 0) {return null;} else {return arraylist;}

} catch (sqlexception e) {system.out.println ("QueryBysql function has SQL error:" E.TOString () ", will return ArrayList set to null"); throw e;} catch (Namingexception E1) {Throw E1;} finally {system.out.println ("QueryBysql function enters Finally sub-block, turn off connection"); try {if (rs! = Null) rclose ();} catch (sqlexception e) {throw E } Try {if (st! = Null) st.close ();} catch (sqlexception e) {throw E;} try {if (conn! = Null) conn.close ();} catch (sqlexception e) { Throw e;} // Return ArrayList; // Description: Do not retrn in Finally, otherwise, the captured error will not be throw! ! ! EmployeeAction.java. This class wraps EJB and is a class that deals with the JSP page. (This Action class, as well as the previous Model class, is a class that derived two main and JSP pages; and the Action class wrapped the EJB, the Model class wrapped the JSP page display element) New Class, named EMPLOYEAAAction, Package Defined as EJBSAMPLE .employee. The content is as follows: package ejbsample.employee;

/ ** * Title: (no title) * Description: The xxaction class is basically EJB packaging. * Copyright: Copyright (c) 2003 * Company: Ebuilds * @author Alex * @version 1.0 * / import ejbsample.SequenceUtil; import ejbsample.EjbCommon; import ejbsample.employee.EmployeeModel; import ejbsample.employee.entity *; import ejbsample. . *; import javax.ejb. *; import javax.naming.namingexception; import java.rmi.remoteException; import java.util.ArrayList; import java.sql. *;

Public class employeaction {

/ ** * Incorporate a Model (no ID this property), automatically add a unique ID, then add a record in the database * @Param model * @return * @throws namingexception * @throws recreateException * / public EmployeeModel add (EmployeeModel model) throws NamingException, RemoteException, CreateException {model.setID (SequenceUtil.getUniteCode ()); action // getUniteCode () is: to give a unique ID number. This function can easily how to write, for example using the current time as ID:. GetTime (); or a network card physical address plus the current time, etc. try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon getRemoteEJBHome (EjbCommon S_EMPLOYEE_JNDI, SbnEmployeeHome.class. ); Sbnemploy.create (); // From the above two lines of code, you can see the format of the session bean encoding: first get the home interface; then call the create () function to get the interface return objremote.insert (model);} / / About error handling: Don't do anything in catch, either you want to turn your catch to the wrong thing, or display some information; otherwise, the program will not debug! Catch (namingexception e) {throw e;} catch (transoteexception e) {throw e;} catch (createExcect e) {throw e;}}

/ ** * Delete a record in the database according to the incoming primary key. * @Param strPk * @return * @throws NamingException * @throws RemoteException * @throws CreateException * / public boolean delete (String strPk) throws NamingException, RemoteException, CreateException, RemoveException, FinderException {try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon. GetRemoteEJBHome (Ejbcommon. S_employeeHome.class); sbnemployee objremote = objhome.create (); boolean b = objremote.del (strpk); returnium;} // About error handling: Must be such a Catch error, then throw go out ! catch (NamingException e) {throw e;} catch (RemoteException e) {throw e;} catch (CreateException e) {throw e;} catch (RemoveException e) {throw e;} catch (FinderException e) {throw e;} }

/ * ** The incoming model, an updated database record inside * @param model * @return * @throws NamingException * @throws RemoteException * @throws CreateException * / public EmployeeModel update (EmployeeModel model) throws NamingException, RemoteException, CreateException , FinderException {try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon getRemoteEJBHome (EjbCommon S_EMPLOYEE_JNDI, SbnEmployeeHome.class.);. SbnEmployee objRemote = objHome.create (); return objRemote.update (model);} catch (NamingException e) {throw e ;} Catch (transoteexception e) {throw e;} catch (createException e) {throw e;} catch (FINDEREXCEPTION E) {throw E;}}

/ * ** The incoming primary key, returns a model * @param strPk * @return * @throws NamingException * @throws RemoteException * @throws CreateException * / public EmployeeModel findByPk (String strPk) throws NamingException, RemoteException, CreateException, FinderException { try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon getRemoteEJBHome (EjbCommon S_EMPLOYEE_JNDI, SbnEmployeeHome.class.);. SbnEmployee objRemote = objHome.create (); return objRemote.findByPk (strPk);} catch (NamingException e) {throw e;} catch (RemoteException e) {throw e;} catch (createExcection e) {throw e;} catch (FINDEREXCEPTION E) {throw e;}}

/ ** * According to the incoming SQL (note is not a complete SQL statement), get all the conditions that meet the condition, put it in an arraylist to return * @Param SQL * @return * @Throws namingexception * @Throws recoteexception * @throws createException * / public ArrayList queryBySql (String sql) throws NamingException, RemoteException, CreateException, SQLException {try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon getRemoteEJBHome (EjbCommon S_EMPLOYEE_JNDI, SbnEmployeeHome.class.);. SbnEmployee objRemote = objHome.create ();

return objRemote.queryBySql (sql);} catch (NamingException e) {throw e;} catch (RemoteException e) {throw e;} catch (CreateException e) {throw e;} catch (SQLException e) {throw e;}}

/ ** * based on the passed array of primary keys, batch delete records * @param sId * @return * @throws NamingException * @throws RemoteException * @throws CreateException * / public boolean deleteBatch (String [] sId) throws NamingException, RemoteException, CreateException {boolean b = false;. try {SbnEmployeeHome objHome = (SbnEmployeeHome) EjbCommon getRemoteEJBHome (EjbCommon S_EMPLOYEE_JNDI, SbnEmployeeHome.class.); SbnEmployee objRemote = objHome.create ();

B = objRemote.delbatch (sID);} catch (namingexception e) {throw e;} catch (recoteexception e) {throw E; CRETEXCEPTION E) {THROW E;} finally {return b;}}

Public EmployeeAction () {} public static void main (string [] args) {EmployeeAction action = new EmployeeAction (); // The following is the debug code. Note: It is best to debug all the methods in the session bean before the EJB released to WebLogics, // Make sure there will be no lower errors. Otherwise, if you go to the JSP page, then debug it, it is undoubtedly nightmare.

Employeemodel Data = New Employeemodel ();

// Description: 1) If you want to debug, as long as you add a "test XX method" and you can. // 2) Sometimes the EJB runs slower, and there is no reaction in JBuilder for a long time. This is to add some // output statements in front of the method, let you know that the program is running correctly.

// * Test the add () method for (int i = 0; i <6; i ) {data.setname ("Name" i); Data.SetJob ("JOB1"); data.sethiRedate (java.sql. Date.Valueof ("2003-07-21"); try {action.add (data);} catch (exception e) {E.PrintStackTrace ();}} // ** // * Test delete () method Try {Action.delete ("ID_2003072504cb077b81059114950140"); // The value of this primary key is found in the database. } Catch (exception e) {E.PrintStackTrace ();} // * /

/ * Test deleteBatch () method String [] strSID = { "ID_2003072504CB077B81059116383421", "ID_2003072504CB077B81059116474625", "ID_2003072504CB077B81059116477218"}; try {action.deleteBatch (strSID);} catch (Exception e) {e.printStackTrace ();} / / * /

/ * Test findByPk () method String strPK = "ID_2003072504CB077B81059116477328"; try {data = action.findByPk (strPK); System.out.println ( "Found name =" data.getName ());} catch (Exception e ) {E.PrintStackTrace ();} // * /

/ * Test queryBysql () method string strsql = "job1 = 'job1'"; arraylist alret = null; try {alret = action.queryBysql (strsql); if (alret! = Null && alret.size ()> 0) { For (int i = 0; i

System.out.println ("********* final!");

}

} Debug EJB: The debugging method is to run the EMPLOYEEAction. Note Before running, you must start WebLogic and ensure that EJB has been published correctly. In fact, the release of EJB should also be commissioned for a long time. Debugging precautions:

Debugging EJB is very troublesome, and it takes a lot of memory. If the memory is not more than 512M or more, it will wait for the pain. Sometimes, all steps are correct, but there are always some strange errors. (For example, when I wrote this example), General ShutDown WebLogic, then remove all temporary directories in the WebLogic directory (generally TMP start), then restart WebLogic. The problem is often able to get resolved. Don't ask why, it is estimated that BEA people don't know. In JBuilder, it is best to remove EJB Module's "Always Creating Jar When Building the Project". So you have to repeat EJB .jar files each time. Sometimes it is compiled. JAR file is large (such as 1M, 2M; general dozens, hundreds of KB is more normal), you have to see if the property settings of EJB Module are correct. Mainly whether Content contains all classes, which generally should choose only the categories that are included. When publishing with JBuilder, sometimes it may encounter a prompt that "more than 4 minutes, time timeout, not success", etc. But it turns out that it is successful, if you encounter this situation, it is ignored. FAQ: Q: Get this error javax.naming.namenotfoundexception: unable to resolve 'sbnemployee' resolved: '' unreSolved: 'sbnemployee'; Remaining Name 'sbnemployee' A: No EJB is released correctly. Please start WebLogic, then right-click EJB Module in JBuilder, select Deploy. Q: Debugged old Tong but A: Restart WebLogic, then try it. Q: I changed the session bean, why didn't it work? A: Modify any part of EJB, you must re-release EJB to take effect. The crux of this problem is likely to be here. But remember, in JBuilder, at this time, use the repline option, do not use deploy. Q: I have system.out.println inside EJB, why can't I see output? A: The output of EJB is in WebLogic. It should be noted that SYSTEM.OUT.PRINTLN output, sometimes in jbuilder, sometimes in WebLogic, sometimes in the Java's console (such as the output of Applet, but this is an external version). Q: My EJB writes correct, why is it always a published error? A: Try: Open the properties of the EJB Module, remove WebLogic-ejb-jar.xml inside "Discriptors in Module" and then re-release. The problem can often be here, especially when you use the weblogic version of WebLogic. Note: This entry can be restored to delete, and JBuilder will automatically add this entry according to the current settings when compiling EJBs.

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

New Post(0)