我早就发布了一个例子啦.下不了吗 ???
http://expert.csdn.net/Expert/TopicView1.asp?id=1627640给我mail,给你一个最新版 :)

解决方案 »

  1.   

    zez(鹤清风 为了老婆多挣钱 !) ,兄弟,下不了了,麻烦你给我发一个吧,多谢了,多谢!
    [email protected]
      

  2.   

    实战JBuilder7+WebLogic7(四)续 JMS+Message-Driven Bean
    刘晓巍: [email protected] 
    第一次写文章,希望大家多多捧场,本文完全根据我的个人经验所写,如有错误,恳请大家指正!JBuilder7+WebLogic7 的配置
    假设Jbuilder7和WebLogic7安装完毕,操作系统为:windows2000 server(SP2),数据库为: SQLServer2000(SP2)。
    JBuilder7的配置:1. 修改环境变量TEMP和TMP 为不带空格的目录如:E:\winnt\temp2. 启动Jbuilder7,选择:Tools->Configure Servers3. 选中左侧的Weblogic Application Server 6.x+,选中右边的Enable Server4. 将General->Home Directory设为WebLogic7的Home Directory如:E:/bea/weblogic700/server,正常的话Jbuilder7将自动为你添好其他的项。5. 将Custom->JDK Installation Directory设为 JDK的安装目录,如:E:/bea/jdk131_026. 将Custom->BEA Home Directory设为WebLogic7的Home Director,如:E:/bea7. 将Custom->Domain Directory设为你的域目录,如:E:/bea/user_projects/mydomain8. 添好User name, Password ,Domain name, Server name后,单击OK退出。9. 选择:Tools->Enterprise Setup,单击CORBA页上的New, 按下表填写相应信息:Name for this configuration = WelLogic 7.0Path for ORB Tools = E:/bea/weblogic700/serverLibrary for Projects = WebLogic 6.x+ DeployIDL compiler command = idlj.exeCommnad option for output directory = E:\CORBAOutput(任意目录,不要有空格)单击OK退出。10.选择Project->Default Project properties在Path页的Required libraries中将会看到WebLogic 6.x+ Client和WebLogic 6.x+ Deploy两项,如果没有,请检查以上步骤是否正确。11.选择Server页,单击Single services for all service in project在下拉列表中选择WebLogic Application Server 6.x+,但击OK退出,配置完毕。
    WebLogic7的配置:1. 启动WebLogic72. 打开IE6,在地址栏中输入:<http://localhost:7001/console>3. 输入用户名和密码4. 在左边的目录树中选中Services->JDBC->Connection Pools,单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:Configuration->General页:Name = SQL Server Connection PoolURL = jdbc:weblogic:mssqlserver4:northwind@localhostDriver classname = weblogic.jdbc.mssqlserver4.DriverProperties : user = saPassword = “” <- sa的密码单击Create建立连接池。Targets->Server页:将myserver(服务器名称)移至右侧的列表中,但击单击Apply5. 在左边的目录树中选中Services->JDBC->Data Sources(或者TXData Sources),单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:Configuration->General页:Name = SQLServer Tx Data SourceJNDI Name = SQLServerPool Name = SQL Server Connection Pool选中Emulate Two-Phase Commit for non-XA Driver和Row Prefetch Enabled单击Create建立数据源。Targets->Server页:将myserver(服务器名称)移至右侧的列表中,但击单击Apply,配置完毕。实战1:连接SQLServer2000
    1. 打开JBuilder7选择File->New project在Name栏中输入SQLServerDemo,Directory栏中输入存放路径(不要有空格),其他不变,单击Finish。2. 选择File->New,选择General->Application,单击OK。第一步,第二步和第三步都不用更改,直接Finish即可。3. 回到JBuilder7的集成开发环境中,单击右侧的Designer页设计窗体,在窗体中放入一个JscrollPane 和JtextArea 及二个按钮,双击第一个按钮输入以下代码:try{Class.forName("weblogic.jdbc.mssqlserver4.Driver");Connection con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:northwind@localhost","sa","");//此处根据你的SQLServer帐户而定。Statement st = con.createStatement();ResultSet res = st.executeQuery("select * from employees");String line = "";while (res.next())line = line + res.getString("title")+"\n";jTextArea1.setText(line);con.close();}catch (Exception ex){jTextArea1.setText("error : "+ex.getMessage());}双击第二个按钮输入以下代码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");//此处是WebLogic7的域用户和密码Statement st = con.createStatement();ResultSet res = st.executeQuery("select * from employees");String line = "";while (res.next())line = line + res.getString("notes")+"\n";jTextArea1.setText(line);con.close();}catch (Exception ex){jTextArea1.setText("error : "+ex.getMessage());}4. 别忘了,在程序开始处加入以下代码:import java.sql.*;import java.util.*;import javax.sql.*;import javax.naming.*;运行WebLogic7,运行程序单击第一个按钮使用JDBC直接连接SQLServer并获取数据,单击第二个按钮使用DataSource连接SQLServer并获取数据。
      

  3.   

    实战2:Session Bean
    建立一个简单的Bean:1. 关闭所有工程:File->Close Projects2. 选择File->New project 在Name栏中输入HelloDemo,Directory栏中输入存放路径(不要有空格),其他不变,单击Finish。3. 选择File->New->Enterprise->EJB 2.0 Designer单击OK。在弹出的对话框中单击new建立一个Moudle,在Name中输入HelloMoudle单击OK关闭当前对话框,再次单击OK关闭对话框。4. 在右侧的工作区中单击右键选择:Create EJB->Session Bean,将Bean Name改为HelloBean5. 右键单击代表HelloBean的长方形,选择Add->Method按如下填写:Method Name = SayHelloReturn Type = java.lang.StringInput parameter 不添Interface = remote6. 右键单击代表HelloBean的长方形,选择 View Bean Source按如下填写SayHello():public java.lang.String SayHello(){/**@todo Complete this method*/return new String(“Hello World “);}7.按F9运行,在弹出的对话框中选择Run页,单击New,在configure name处填写Server Runtime Configuration,再选择Run->Server,单击OK关闭当前对话框,单击OK开始编译运行。运行起来之后在左上角的目录树中右键单击HelloModule选择:Deploy options for “HelloModule.jar”->Deploy来发布Bean。建立客户端:1. 选择File->New->Enterprise->EJB Test Client单击OK。选中Genrate method for Default remote interface calls with default arguments单击OK。2. 按如下填写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());} 选择Run->Run “HelloBeanTestClient1.java” using defaults运行。实战3:Entity Bean
    配置Weblogic for SQL Server JDBC Driver :1. 选择:Tools->Enterprise Setup,单击Database Drivers页上的Add, 在弹出的对话框中单击New,. 在弹出的对话框中填写Name为WebLogic for SQL Server, Location选择User Home,单击Add按钮,选择weblogic.jar,例如:F:\bea\weblogic700\server\lib\weblogic.jar, 单击OK关闭当前对话框,可以看到WebLogic for SQL Server已被加入,单击OK关闭当前对话框,再次单击OK,配置完成。重起Jbuilder 7。建立一个简单的CMP Entity Bean :1. 关闭所有工程:File->Close Projects2. 选择File->New project 3. 在Name栏中输入CMPDemo,Directory栏中输入存放路径(不要有空格),其他不变,单击Finish。4. 选择File->New->Enterprise->EJB Module单击OK。在弹出的对话框中,在Name中输入CMPMoudle, Version选择:EJB2.0 Compliant其余不变,单击OK关闭当前对话框。5. 右键单击屏幕左下角的DataSources,选择Import Schema From Database,在弹出的对话框中,按如下填写:选中 All Schemas和ViewsDriver选择weblogic.jdbc.mssqlserver4.DriverURL= jdbc:weblogic:mssqlserver4:northwind@localhost:1433UserName=saPassword=”” / /此处为sa密码JNDI Name= SQLServer单击OK,如果设置正缺的话,DataSources下将会出现名为SQLServer的Datasource6. 单击名为SQLServer的Datasource左边的加号将其展开,将会看到所有的表和视图。7. 右键单击Employees表,选择Create CMP 2.0 Entity Bean8. 单击代表Employees表的长方形顶部的Employees,在右侧弹出的面板中将Interfaces选为local/remote,选择File->Save All保存全部项目。9. 选择Project->Make ”CMPModule”, 编译成功后,右键单击左上角的CMPModule选择Deploy Options for ”CMPModule.jar”->Deploy,将其发布至Weblogic。建立客户端:1. 选择File->New->Enterprise->EJB Test Client单击OK。选中Genrate method for Default remote interface calls with default arguments单击OK。3. 按如下填写main():public static void main(String[] args){EmployeesTestClient1 client = new EmployeesTestClient1();client.findByPrimaryKey(new Integer(1));if (client.employeesRemote == null){System.out.println("Error in testRemoteCallsWithDefaultArguments(): " + ERROR_NULL_REMOTE);return ;}client.getEmployeeID();client.getLastName();client.getFirstName();client.getTitle();client.getTitleOfCourtesy();client.getBirthDate();client.getHireDate();client.getAddress();client.getCity();client.getRegion();client.getPostalCode();client.getCountry();client.getHomePhone();client.getExtension();client.getPhoto();client.getNotes();client.getReportsTo();client.getPhotoPath();}选择Run->Run “EmployeesBeanTestClient1.java” using defaults运行。实战4:JMS
    配置Weblogic1. 启动WebLogic72. 打开IE6,在地址栏中输入:<http://localhost:7001/console>3. 输入用户名和密码4. 在左边的目录树中选中Services->JMS->Connection Factories,单击右侧的Configure a new JMS Connection Factory ,输入以下信息:Configuration->General页:Name = MDBDemo Connection FactoryJNDIName= MDBDemoCF其它不变,单击Create建立Connection Factory。Targets->Server页:将myserver(服务器名称)移至右侧的列表中,但击单击Apply5. 在左边的目录树中选中Services->JMS->Stores,单击右侧的Configure a new JMSFileStore,输入以下信息:Configuration->General页:Name = MDBDemo StoreDirectory: = F:\bea\user_projects\mydomain\JMSStores (任意存在的目录即可)单击Create建立JMSFileStore。6. Services->JMS->Servers,单击右侧的Configure a new JMS Connection Factory ,输入以下信息:Configuration->General页:Name = MDBDemo JMSServerStore = MDBDemo Store其它不变,单击Create建立JMS Server。Targets->Servers页:Target = myserver(你的weblogic server的名字)单击Configuration->General页中的Configure DestinationsName = MDBDemo TopicJNDIName= MDBDemo Topic其它不变,单击Create建立Destination。配置完毕。建立Message Driven Bean:1. 关闭所有工程:File->Close Projects2. 选择File->New project 3. 在Name栏中输入MDBDemo,Directory栏中输入存放路径(不要有空格),其他不变,单击Finish。4. 选择File->New->Enterprise->EJB Module单击OK。5. 在弹出的对话框中,在Name中输入MDBMoudle, Version选择:EJB2.0 Compliant其余不变,单击OK关闭当前对话框。6. 在右侧的EJB Designer 中单击鼠标右键选择:Create EJB->Message-Driven Bean,按如下填写:Bean Name = MDBDemoTransaction Type = ContainerDestination Name = MDBDemo TopicDestination Type = javax.jms.Topic其它不变。7.Project->Make ”MDBModule”, 编译成功后,右键单击左上角的MDBModule选择Deploy Options for ”MDBModule.jar”->Deploy,将其发布至Weblogic。
      

  4.   

    建立客户端:以下是客户端源码,保存成TestClient.java加入工程后,选择Run->Run “TestClient.java” using defaults运行即可,可以在weblogic console窗口看到输出。如果看不到输出,重起weblogic试一试。package mdbdemo;
    import java.rmi.RemoteException;import java.util.Properties;
    import javax.jms.JMSException;import javax.jms.Message;import javax.jms.Session;import javax.jms.TextMessage;import javax.jms.Topic;import javax.jms.TopicConnection;import javax.jms.TopicConnectionFactory;import javax.jms.TopicPublisher;import javax.jms.TopicSession;
    import javax.ejb.CreateException;import javax.ejb.RemoveException;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;import javax.rmi.PortableRemoteObject;
    /*** This class illustrates calling a Message-Driven bean and publishing* quotes on a topic.** @author Copyright (c) 1998-2002 by BEA Systems, Inc. All Rights Reserved.*/
    public class TestClient {static private String TOPIC_NAME = "MDBDemo Topic";
    private String m_url;
    private Context m_context;private TopicConnection m_topicConnection;
    public TestClient(String url)throws NamingException{m_url = url;
    try {//// Create a context//m_context = getInitialContext();
    //// Create the connection and start it//TopicConnectionFactory cf =(TopicConnectionFactory) m_context.lookup("MDBDemoCF");m_topicConnection = cf.createTopicConnection();m_topicConnection.start();
    }catch(Exception ex) {ex.printStackTrace();}}/*** Runs this example from the command line. Example:* <p>* <tt>java examples.ejb20.message.Client "t3://localhost:7001"</tt>* <p>* The parameters are optional, but if any are supplied,* they are interpreted in this order:* <p>* @param url URL such as "t3://localhost:7001" of Server*/public static void main(String[] args) throws Exception {
    log("\nBeginning message.Client...\n");
    String url = "t3://localhost:7001";
    TestClient client = null;try {client = new TestClient(url);} catch (NamingException ne) {System.exit(1);}
    try {client.example();}catch (Exception e) {log("There was an exception while creating and using the MDB.");log("This indicates that there was a problem communicating with the server: "+e);//e.printStackTrace();}
    log("\nEnd message.Client...\n");}
    /*** Runs this example.*/public void example()throws RemoteException, JMSException, NamingException{Topic newTopic = null;TopicSession session = null;try {session =m_topicConnection.createTopicSession(false, // non transactedSession.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);}}/*** Using a Properties object will work on JDK 1.1.x and Java2* clients*/private Context getInitialContext() throws NamingException {
    try {// Get an InitialContextProperties 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) {log("We were unable to get a connection to the WebLogic server at "+m_url);log("Please make sure that the server is running.");throw ex;}}
    /*** This is the Java2 version to get an InitialContext.* This version relies on the existence of a jndi.properties file in* the application's classpath.**/// private static Context getInitialContext()// throws NamingException// {// return new InitialContext();// }
    private static void log(String s) {System.out.println(s);}
    }实战5:JSP调用EJB
    (待续)
      

  5.   

    [email protected] 谢谢!!
      

  6.   

    谁要去我的连接里留mail.这里我偶尔来了才看到你们的...
    我要不来.留这不也没用吗:)
      

  7.   

    zez(鹤清风 为了老婆多挣钱 !) 多谢你了!