我倒是有个Weblogic702的,连接JBuilder9和Oracle817NT
//TestSessionBean.java------------------------------------------------0
package test;import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;public class TestSessionBean
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 java.util.Vector GetDataDirect(String strUser, String strPassword) {
Vector vec = new Vector();
try {
//connect to Database
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection dbConn = DriverManager.getConnection(
"jdbc:oracle:thin:@baixiaoyong:1521:baixy", "system", "manager");
Statement stmt = dbConn.createStatement(); ResultSet rs = null;
String strSql; //Table emp
strSql = new String("select * from student");
rs = stmt.executeQuery(strSql); //put the resultSet to Vector
while (rs.next()) {
vec.addElement(rs.getString(1));
vec.addElement(rs.getString(2));
vec.addElement(rs.getString(3));
}
//close the connection
rs.close();
stmt.close();
dbConn.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
return vec;
}
}}
//TestSessionTestClient.java-----------------------------------------1
//写进main函数
try
{
TestSessionTestClient client = new TestSessionTestClient();
TestSession remote = (TestSession) client.getHome().create();
System.out.print(remote.GetDataDirect("system","manager"));
}
catch (Exception ex)
{
ex.printStackTrace();
}//TestServlet.java------------------------------------------------------2
package test;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class TestServlet
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String var0 = request.getParameter("strUser");
if (var0 == null) {
var0 = "";
}
String var1 = request.getParameter("strPassword");
if (var1 == null) {
var1 = "";
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>TestServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a " + request.getMethod() +
". This is the reply.</p>");
out.println("</body></html>");
} //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String var0 = request.getParameter("strUser");
if (var0 == null) {
var0 = "";
}
String var1 = request.getParameter("strPassword");
if (var1 == null) {
var1 = "";
} response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String suserName, spassWord;
suserName = request.getParameter("userName");
spassWord = request.getParameter("passWord"); out.println("<html>");
out.println("<head><title>TestServlet</title></head>");
out.println("<body fontsize=2 fontface=verdana bgcolor=\"#ffffff\">");
out.println("<p>This is a test.</p>");
try {
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("TestSession");
TestSessionHome testhome = (TestSessionHome) javax.rmi.
PortableRemoteObject.narrow(obj, TestSessionHome.class);
TestSession test = testhome.create();
Vector v = test.GetDataDirect(suserName, spassWord);
out.println("Count of ResultSet in your condition: ");
out.println(v.size());
out.println("<br><br>");
String s1 = null, s2 = null, s3 = null, s4 = null;
out.println("<table border=1 width=300 align=left>");
s1 = "id";
s2 = "name";
s3 = "age";
String outString = "";
outString += "<tr><td align=25%>" + s1 + "</td>";
outString += "<td align=25%>" + s2 + "</td>";
outString += "<td align=25%>" + s3 + "</td></tr>";
out.println(outString); for (int i = 0; i < v.size(); i++) {
s1 = String.valueOf(v.get(i++));
s2 = String.valueOf(v.get(i++));
s3 = String.valueOf(v.get(i)); outString = "";
outString += "<tr><td align=25%>" + s1 + "</td>";
outString += "<td align=25%>" + s2 + "</td>";
outString += "<td align=25%>" + s3 + "</td></tr>";
out.println(outString); }
out.println("</table>");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
out.println("</body></html>");
}
} //Clean up resources
public void destroy() {
}
}
//TestSessionBean.java------------------------------------------------0
package test;import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;public class TestSessionBean
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 java.util.Vector GetDataDirect(String strUser, String strPassword) {
Vector vec = new Vector();
try {
//connect to Database
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection dbConn = DriverManager.getConnection(
"jdbc:oracle:thin:@baixiaoyong:1521:baixy", "system", "manager");
Statement stmt = dbConn.createStatement(); ResultSet rs = null;
String strSql; //Table emp
strSql = new String("select * from student");
rs = stmt.executeQuery(strSql); //put the resultSet to Vector
while (rs.next()) {
vec.addElement(rs.getString(1));
vec.addElement(rs.getString(2));
vec.addElement(rs.getString(3));
}
//close the connection
rs.close();
stmt.close();
dbConn.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
return vec;
}
}}
//TestSessionTestClient.java-----------------------------------------1
//写进main函数
try
{
TestSessionTestClient client = new TestSessionTestClient();
TestSession remote = (TestSession) client.getHome().create();
System.out.print(remote.GetDataDirect("system","manager"));
}
catch (Exception ex)
{
ex.printStackTrace();
}//TestServlet.java------------------------------------------------------2
package test;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class TestServlet
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
//Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String var0 = request.getParameter("strUser");
if (var0 == null) {
var0 = "";
}
String var1 = request.getParameter("strPassword");
if (var1 == null) {
var1 = "";
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>TestServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a " + request.getMethod() +
". This is the reply.</p>");
out.println("</body></html>");
} //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String var0 = request.getParameter("strUser");
if (var0 == null) {
var0 = "";
}
String var1 = request.getParameter("strPassword");
if (var1 == null) {
var1 = "";
} response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String suserName, spassWord;
suserName = request.getParameter("userName");
spassWord = request.getParameter("passWord"); out.println("<html>");
out.println("<head><title>TestServlet</title></head>");
out.println("<body fontsize=2 fontface=verdana bgcolor=\"#ffffff\">");
out.println("<p>This is a test.</p>");
try {
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("TestSession");
TestSessionHome testhome = (TestSessionHome) javax.rmi.
PortableRemoteObject.narrow(obj, TestSessionHome.class);
TestSession test = testhome.create();
Vector v = test.GetDataDirect(suserName, spassWord);
out.println("Count of ResultSet in your condition: ");
out.println(v.size());
out.println("<br><br>");
String s1 = null, s2 = null, s3 = null, s4 = null;
out.println("<table border=1 width=300 align=left>");
s1 = "id";
s2 = "name";
s3 = "age";
String outString = "";
outString += "<tr><td align=25%>" + s1 + "</td>";
outString += "<td align=25%>" + s2 + "</td>";
outString += "<td align=25%>" + s3 + "</td></tr>";
out.println(outString); for (int i = 0; i < v.size(); i++) {
s1 = String.valueOf(v.get(i++));
s2 = String.valueOf(v.get(i++));
s3 = String.valueOf(v.get(i)); outString = "";
outString += "<tr><td align=25%>" + s1 + "</td>";
outString += "<td align=25%>" + s2 + "</td>";
outString += "<td align=25%>" + s3 + "</td></tr>";
out.println(outString); }
out.println("</table>");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
out.println("</body></html>");
}
} //Clean up resources
public void destroy() {
}
}
<form method="post" action = "TestServlet"> //这里有时Jbuilder默认第一个字母是小写,如果出现问题,可以看看WEB.xml里面是怎样定义的。
<br><br>
<input type="text" name="userName" value=""><br><br>
<input type="text" name="passWord" value=""><br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">//TestSessionBean.java----------------------------------------------4(再次改写TestSessionBean)
package test;import javax.ejb.*;
import java.rmi.*;
import javax.naming.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;
import javax.rmi.PortableRemoteObject;public class TestSessionBean
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 java.util.Vector GetDataDirect(String strUser, String strPassword) {
Vector vec = new Vector();
try {
//connect to Database
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection dbConn = DriverManager.getConnection(
"jdbc:oracle:thin:@baixiaoyong:1521:baixy", "system", "manager");
Statement stmt = dbConn.createStatement(); ResultSet rs = null;
String strSql; //Table emp
strSql = new String("select * from student");
rs = stmt.executeQuery(strSql); //put the resultSet to Vector
while (rs.next()) {
vec.addElement(rs.getString(1));
vec.addElement(rs.getString(2));
vec.addElement(rs.getString(3));
}
//close the connection
rs.close();
stmt.close();
dbConn.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
return vec;
}
} public java.util.Vector GetDataFromCMP(String strField) {
Context ctx;
//Vector vctTable = null; //
Vector vctTable = new Vector();
ResultSet result = null;
try {
ctx = new InitialContext();
Object ref = ctx.lookup("TestCMPRemote");
TestCMPRemoteHome remoteHome =
(TestCMPRemoteHome) PortableRemoteObject.narrow(
ref, TestCMPRemoteHome.class);
Iterator it = remoteHome.findByName("").iterator();
if (it == null) {
System.out.println("no data found in Dep");
return null;
}
//vctTable = new Vector(1,1); (注释掉)
TestCMPRemote tr;
while (it.hasNext()) {
tr = (TestCMPRemote) it.next();
vctTable.add(tr.getId()); ////////改为getID,name,age
vctTable.add(tr.getName());
vctTable.add(tr.getAge());
}
}
catch (Exception e) {
e.printStackTrace();
}
return vctTable;
}}
//TestClient.java
package test;import javax.swing.UIManager;
import java.awt.*;import java.rmi.*;
import java.util.*;
import javax.jms.*;
import javax.ejb.*;
import javax.naming.*;
public class TestClient {
boolean packFrame = false; static private String TOPIC_NAME = "TestDestination";
static private String m_url = "t3://localhost:7001";
private Context m_context;
private TopicConnection m_topicConnection;
//Construct the application
public TestClient(String url) {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
//
m_url = url;
try {
m_context = getInitialContext();
TopicConnectionFactory cf =
(TopicConnectionFactory) m_context.lookup("TestJmsConnection");
m_topicConnection = cf.createTopicConnection();
m_topicConnection.start();
}
catch(Exception ex) {
ex.printStackTrace();
} } //Main method
public static void main(String[] args) {
System.out.println("\nBeginning message.Client...\n");
String url = "t3://localhost:7001";
TestClient client = null;
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
client = new TestClient(url);
client.Test();
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("\nEnd message.Client...\n");
// new TestClient();
}
public void Test()
throws RemoteException, JMSException, NamingException
{
Topic newTopic = null;
TopicSession session = null;
try {
session = m_topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
newTopic = (Topic) m_context.lookup(TOPIC_NAME);
}
catch(NamingException ex) {
newTopic = session.createTopic(TOPIC_NAME);
m_context.bind(TOPIC_NAME, newTopic);
} TopicPublisher sender = session.createPublisher(newTopic);
TextMessage tm = session.createTextMessage();
String[] quotes = new String[] {
"BEAS 40 1/8", "SUNW 79 1/2", "IBM 82 1/4", "Hello !"
}; for (int i = 0; i < quotes.length; i++) {
tm.setText(quotes[i]);
sender.publish(tm);
System.out.println(quotes[i]);
}
} private Context getInitialContext() throws NamingException {
try {
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, m_url);
return new InitialContext(h);
}
catch (NamingException ex) {
ex.printStackTrace();
return null;
}
}
}
//SessionBean**********************************************1、Test----------------------------------------------project
2、TestModule----------------------------------------EJB Module
3、TestSession------------------------------------------Method
名 称: GetDataDirect
返回值类型: java.util.Vector
参 数: String strUser,String strPassword
接口 属性: remote
4、TestSessionBean.Java------------------------------copy code
5、TestModule----------------------------------------编译,部署
6、JDBC Connection Pool -----------------------------配置数据库连接池
Name(任意填): TestJDBConnectionPool
URL: jdbc:oracle:thin:@zhuyu:1521:ufaser
Driver Classname: oracle.jdbc.driver.OracleDriver
Properties: user=system
password=manager
7、JDBC Data Source----------------------------------配置数据源
Name: TestDataSource (任意写)
JNDI Name: TestJNDIname (任意写)
PoolName: TestJDBConnectionPool (对应数据库连接池的名字)
8、TestSessionTestClient------------------------------EJB Test Client,copy 代码1
9、TestJNDIname---------------------------------------TestModule\JDBC 1 Datasources
URL: jdbc:oracle:thin:@baixiaoyong:1521:baixy
Driver Name: oracle.jdbc.driver.OracleDriver
10、TestSessionTestClient------------------------------运行
11、TestWeb--------------------------------------------Web Application
12、TestServlet----------------------------------------Servlet, copy code
13、TestJsp--------------------------------------------JavaServer Page,copy code
14、TestWeb--------------------------------------------部署
15、TestServer-----------------------------------------配置运行环境
16、运行TestJsp.jsp
//EntityBean****************************************************************1、TestTxDataSource------------------------------------“JDBC\Tx Data Source”节点
Name: TestTxDataSource (任意写)
JNDI Name: TestDSJndi (任意写)
PoolName: TestJDBConnectionPool (对应数据库连接池的名字)
2、GetDataFromCMP---------------------------------------“TestSession”
返回值类型是java.util.Vector, 参数是String strTest。
3、 在JDBC 1 DataResource中添加 TestDSJndi
4、TestDSJndi------------------------------------------“TestModule”窗口的“Import Schema From Database”,“TestTxDataSource”
5、TestCMP--------------------------------------------------CMP实体Bean
6、id,name,age----------------------------------------------Method
7、findByName-----------------------------------------------finder
Return type: java.util.Collection
Input parameters: String strTest
SELECT OBJECT(x) FROM TestCMP AS x
8、TestSessionBean.java-------------------------------------再次拷贝
9、TestServlet.java-----------------------------------------替换
Vector v = test.GetDataFromCMP("");
10、TestCMPRemote--------------------------------------------Entity Bean TestCMP
11、编译、部署、运行
//MDB************************************************************
1、TestJMSConnectionFactory-----------------------------?ConnectionFactories
JNDIName: TestJmsConnection
2、TestJMSFileStore------------------------------------ FileStores
Directory: D:\bea\user_projects\mydomain2\jms
3、TestJMSServer------------------------------------------Servers
TestJMSFileStore
4、TestJMSTopic-------------------------------------------? Destinations -> JMSTopics
JNDIName: TestDestination
5、Test工程
6、TestModule
7、TestMessageBean--------------------------------------------MDB
Destination name: TestDestination
Connection factory name: TestJmsConnection
8、消息处理函数
public void onMessage(Message msg) {
System.out.println(msg);
System.out.println(msg);
}
9、编译和部署TestMessageBean
10、运行TestClient--------------------------------------Application,copy code
weblogic,jbuider不敢望啊急急,在线等
比如path="seds",
DEBUG servlet.JspServlet (JspServlet.java:120) - Scratch dir for the JSP engine
is: E:\tomcat\work\Catalina\localhost\seds
DEBUG servlet.JspServlet (JspServlet.java:122) - IMPORTANT: Do not modify the g
enerated servlets
2004-6-22 16:17:07 org.apache.catalina.core.StandardHost getDeployer
信息: Create Host deployer for direct deployment ( non-jmx )
2004-6-22 16:17:07 org.apache.catalina.core.StandardHostDeployer install
信息: Processing Context configuration file URL file:E:\tomcat\conf\Catalina\loc
alhost\admin.xml
DEBUG startup.TldConfig (TldConfig.java:612) - Accumulating TLD resource paths
DEBUG startup.TldConfig (TldConfig.java:619) - Scanning <taglib> elements in
web.xml
DEBUG startup.TldConfig (TldConfig.java:665) - Scanning TLDs in /WEB-INF subd
irectory
DEBUG startup.TldConfig (TldConfig.java:680) - Adding path '/WEB-INF/control
s.tld'
DEBUG startup.TldConfig (TldConfig.java:680) - Adding path '/WEB-INF/struts-
bean.tld'
DEBUG startup.TldConfig (TldConfig.java:665) - Scanning TLDs in /WEB-INF/stru
ts-config.xml subdirectory
DEBUG startup.TldConfig (TldConfig.java:680) - Adding path '/WEB-INF/struts-
html.tld'
DEBUG startup.TldConfig (TldConfig.java:680) - Adding path '/WEB-INF/struts-
logic.tld'
DEBUG startup.TldConfig (TldConfig.java:665) - Scanning TLDs in /WEB-INF/web.
xml subdirectory
DEBUG startup.TldConfig (TldConfig.java:407) - Last modified /WEB-INF/struts-lo
gic.tld 1076754098000
DEBUG startup.TldConfig (TldConfig.java:407) - Last modified /WEB-INF/controls.
tld 1076754098000
DEBUG startup.TldConfig (TldConfig.java:407) - Last modified /WEB-INF/struts-ht