JBuilder7 Welogic6.1 Oracle8i
A stateless session bean connection WebLogic database connection pool takes a field value of the Oracle a table returns to the client (servlet)
These, NOW is sorted into notes.
1. Confirm that the installation or WebLigc 6.1 .jbuilder7 is the default installation 2. Start configuring the JBuilder7 and WebLogic connection. I refer to the configuration of jbuilder6, with a small difference between JB7 a. Open Tools -> Configue Servers -> Select WebLogic6 .x enable Server tick Select the correct weblgic installation path Note that the display resolution is 1024 * 768 to see the following OK button is the same as: D: /bea/wlserver6.1 in the Custom page of Home DIRECTORY Fill in the WebLogic boot password Other default b. Open Tools -> Enterprise Setup -> CORBA New A program that is called WebLogic Under Path for ORB Tools Add to Weblogic 6.x Delop Under Library for Project Fill in the COMPILER Command in Command ... for Oupput Dircery Fill in a self ... for Oupput Dircery Fill in your own output path C Final confirmation Projects -> Default Projects Properties -> Server selected Application Server is WebLogic 6.x File: // should be yes, then look at D Final to my computer point right click to modify system variables Temp and TMP because the default directory name has space, JB7 allergy, change to a directory of no space, such as C: / Temp is of course You have to build this directory first 3. Create an Oracle connection pool in WebLogic. In WebLogic Console Services -> JDBC -> Connection Po OLS -> Configure a new JDBC Connection Pool In the General Property page name: Connection pool name File: // I have been named TestPool, Note Name Case Size URL: JDBC Connection String File: // Oracle: JDBC: Oracle: Thin: @xiw: 1521: SDB XIW can also use the server name to the server name Driver ClassName: Fill in Oracle.jdbc.driver.OracleDriver Properties: Fill in User = System File: / / That is, Oracle's username, you can also fill in password password, please fill in the clicking Apply // WebLogic if there is icon flashing,
Indicates that you need to restart WebLigoc settings will not be explained later. Then click PASSWORD Enter the database password in the Connection page Initial Capacity: 1 file: // Initial connection Maximum Capacity: 10 File: // Maximum connection number Capacity Increment: 1 // Initial insufficient At each time, each time it increases the number of connections: 5 file: / / Prevent the network accident interruption, refresh the connection every 5 minutes, automatically restore other defaults in the Testing page test table name: Tab // Oracle already has this Table, with other Oracle system tables, the following two selection tabs indicate that the accident is enabled, the automatic refresh recovery connection icon flashes, indicates that you need to restart WebLigoc after restart: in: Serviers -> JDBC -> Connection Pools -> TestPool Page Target Page Move MyServer to Chosen Middle Point Apply File: // Indicates that server enabled if there is an error, usually the previous URL error or there is no Testing specified, I have been like this Need to restart and then to Services -> JDBC -> Data Source Configure A New JDBC Data Source TestPool file: // The name of the pool built in front and then click Apply on the target page, and moves with MyServer to Chosen Apply. At this time, if there is an error, the WebLogic completion is usually restarted to connect to the pool name. 4 Start program • Newly built an empty item in JB7 · Enterprise page EJB2.0 Bean Designer in New Sense Design Window, Right-click New Session Bean, the name is Testsqlbean Type for Stateless • Launch Oralce · Add a table Table3 field name A1 plus a data 'Okok' file: // Finally returns Okok in the servlet to success · New Class in the project, as return The result is used, the class is serialized this class named TestString code, which is more rough, not optimized, in fact, can be directly returned, and see it.
package testpool; import javax.ejb *;. import java.sql *;. import javax.sql *;. public class TestString implements java.io.Serializable {private String returnS; public TestString (String ss) {returnS = ss;}
Public String Returnstr () {Return Returns;} Public String Geta1 (DataSource DS, String SQL) {String Temp = "NONO"; file: // The default is that if it returned this, it is a failure of try {connection conn = ds.getConnection (); Statement stmt = conn.createstatement (); stmt.executeQuery (SQL); ResultSet RS = stmt.getResultSet (); int i = rs.getrow (); file: // Didn't display change, debugging See if (rs.next ()) {temp = rs.getstring (1);}}}}} (); conn.close ();} catch (exception e) {E.PrintStackTrace ();} return temp; } · The following modified Testsqlbean.java needs to add some type of IMPORT JAVA.SQL. *; Import javax.sql. *; Other Home interface or remote interface to join the RESULTSET, Datasource to add it, no longer repeat the addition of several properties String returnString; DataSource ds; · ejbCreate also need to modify the code testsqlbean: public void ejbCreate () throws CreateException {try {Context ctx = new InitialContext (); ds = (DataSource) ctx.lookup ( "MyJNDI"); // MyJNDI WEBLOGIC JD configured for front BC's JNDI name} catch (exception e) {}}. Right click on the visual design window Testsqlbean on the TestString parameter for the getMyConn returns the TestString parameter for the front SQL Finally modified the function code as follows: public teststring getMyConn (String SQL) {Teststring T1 = New Teststring (SQL); String Returnstring = T1.GETA1 (DS, SQL); Return New TestString (Returnstring);} After Make Project After compiling · On the list of project files, click Web Run to start WebLogic to start WebLogic to start it if There is no error, then EJB is automatically deployed to WebLogic, and a servlet is a servlet with JB7, a servlet is called TestPoolServlet all code. Package TestPool;
Import javax.servlet. *; import javax.servlet.http. *; import java.io. *; import java.sql. *; import java.util. *; import javax.naming. *; Import javax.ejb. * ; import java.rmi.RemoteException; import java.rmi.Remote; import testpool.testsql; import testpool.testsqlHome; public class testpoolServlet extends HttpServlet {static final private String CONTENT_TYPE = "text / html; charset = GBK"; TestVector myStr;
file: // Initialize global variables public void init () throws ServletException {} file: // Process the HTTP Get request public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType (CONTENT_TYPE); String sql = "Select * from table3"; file: // client gives EJB SQL statement printwriter out = response.getwriter (); out.println (""); out.println (""); out.println ("") Out.println ("
"); Try {Context context = new InitialContext (); Object objref = context.lookup (" testsqlBean "); // EJB in the SessionBean name testsqlHome home = (testsqlHome) javax.rmi.PortableRemoteObject.narrow (objref, testsqlHome .class; testsql servletsql = home.create (); teststring mytstr = servletsql.getMYCONN (SQL); string mystr = mytstr.returnstr (); Out.println ("
THIS IS == " MYSTR " "); Out.Println ("
");
Out.println ("
"The servlet Has Received A Get. This is the reply.");
OUT.PRINTLN ("");
} catch (exception e) {
Out.println ("A Problem Has Occurred with the servlet.");
}
}