實戰JBuilder7+WebLogic7(續Session bean) (轉)
實戰JBuilder7+LOGIC7存取MS SERVER2000(一)
劉曉巍: to:liuxiaowei2000@sina.com">liuxiaowei2000@sina.com
:namespace prefix = o ns = "urn:schemas--com::office" />
第一次寫文章,希望大家多多捧場,本文完全根據我的個人所寫,如有錯誤,懇請大家指正!
JBuilder7+WebLogic7 的
假設Jbuilder7和WebLogic7完畢,操作為:2000 server(SP2),為: SQLServer2000(SP2)。
JBuilder7的配置:
1. 修改環境變數TEMP和TMP 為不帶空格的目錄如:E:winnttemp
2. 啟動Jbuilder7,選擇:Tools->Configure Servers
3. 選中左側的Weblogic Application Server 6.x+,選中右邊的Enable Server
4. 將General->Home Directory設為WebLogic7的Home Directory如:E:/bea/weblogic700/server,正常的話Jbuilder7將自動為你添好其他的項。
5. 將Custom-> Installation Directory設為 JDK的安裝目錄,如:E:/bea/jdk131_02
6. 將Custom->BEA Home Directory設為WebLogic7的Home Director,如:E:/bea
7. 將Custom->ain Directory設為你的域目錄,如:E:/bea/user_projects/mydomain
8. 添好User name, Pass ,Domain name, Server name後,單擊OK退出。
9. 選擇:Tools->Enterprise Setup,單擊頁上的New, 按下表填寫相應資訊:
Name for this configuration = WelLogic 7.0
Path for ORB Tools = E:/bea/weblogic700/server
Library for Projects = WebLogic 6.x+ Deploy
IDL compiler command = idlj.exe
Commnad 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. 啟動WebLogic7
2. 開啟,在位址列中輸入:
3. 輸入名和密碼
4. 在左邊的目錄樹中選中Services->JC->Connection Pools,單擊右側的Configure a new Connection Pool.,輸入以下資訊:
Configuration->General頁:
Name = Connection Pool
URL = jdbc:weblogic:mssqlserver4:northwind@localhost
classname = weblogic.jdbc.mssqlserver4.Driver
Properties : user = sa
Password = “”
單擊Create建立連線池。
Targets->Server頁:
將myserver(名稱)移至右側的列表中,但擊單擊Apply
5. 在左邊的目錄樹中選中Services->JDBC->Data s(或者TXData Sources),單擊右側的Configure a new JDBC Connection Pool.,輸入以下資訊:
Configuration->General頁:
Name = SQLServer Tx Data Source
JNDI Name = SQLServer
Pool 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(" * 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.PROVR_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());
}
執行WebLogic7,執行單擊第一個按鈕使用JDBC直接連線SQLServer並獲取資料,單擊第二個按鈕使用DataSource連線SQLServer並獲取資料。
實戰2:Session Bean
建立一個簡單的Bean:
1. 關閉所有工程:File->Close Projects
2. 選擇File->New project
在Name欄中輸入HelloDemo,Directory欄中輸入存放路徑(不要有空格),其他不變,單擊Finish。
3. 選擇File->New->Enterprise-> 2.0 Designer單擊OK。
在彈出的對話方塊中單擊new建立一個Moudle,在Name中輸入HelloMoudle單擊OK關閉當前對話方塊,再次單擊OK關閉對話方塊。
4. 在右側的工作區中單擊右鍵選擇:Create EJB->Session Bean,將Bean Name改為HelloBean
5. 右鍵單擊代表HelloBean的長方形,選擇Add->Method
按如下填寫:
Method Name = SayHello
Return Type = .lang.String
Input parameter 不添
Interface = remote
6. 右鍵單擊代表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 特斯廷remote interface calls with default arguments單擊OK。
2. 按如下填寫main():
public static void main(String[] args)
{
HelloBeanTestClient1 client = new HelloBeanTestClient1();
// Use the client 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執行。來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-990039/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DVWA靶場實戰(九)——Weak Session IDSSession
- shiro實戰系列(二)之入門實戰續
- 【轉】微服務實戰微服務
- Spring的學習與實戰(續)Spring
- 終於搞懂Spring中Scope為Request和Session的Bean了SpringSessionBean
- TiDB 在轉轉的業務實戰TiDB
- 持續整合之 Spring Boot 實戰篇Spring Boot
- java將map轉成bean工具JavaBean
- spring4.1.8擴充套件實戰之六:註冊bean(BeanDefinitionRegistryPostProcessor)Spring套件Bean
- spring4.1.8擴充套件實戰之七:控制bean(BeanPostProcessor介面)Spring套件Bean
- Cloud Foundry Session Affinity(Sticky Session)的實現CloudSession
- 1、實戰SSH埠轉發
- UI自動化實戰進階後續UI
- mysql sql 中實戰小技巧持續更新MySql
- stored procedure 收集session wait 資訊(轉)SessionAI
- 轉轉:微信小程式分包載入實戰微信小程式
- 分享一個session過期後根據guard跳轉的實現Session
- Kubernetes實戰總結 - DevOps實現(轉載)dev
- ASP.NET Core 專案實戰(持續更新~~~)ASP.NET
- client-go實戰之六:時隔兩年,重新整理版本繼續實戰clientGo
- 實戰開發,使用 Spring Session 與 Spring security 完成網站登入改造!!SpringSession網站
- SpringBoot2.x 整合Spring-Session實現Session共享Spring BootSession
- 日常問題 頁面跳轉 $_SESSION 失效Session
- client-go實戰之七:準備一個工程管理後續實戰的程式碼clientGo
- Tomcat中的session實現TomcatSession
- Spark綜合使用及使用者行為案例訪問session統計分析實戰-Spark商業應用實戰SparkSession
- 設定 SSH 隧道(埠轉發)實戰
- 實戰|教你用Python玩轉MysqlPythonMySql
- 【原創】如何優雅的轉換Bean物件Bean物件
- JWT簡介:從Session到Token的轉變JWTSession
- spring4.1.8擴充套件實戰之五:改變bean的定義(BeanFactoryPostProcessor介面)Spring套件Bean
- oracle行轉列、列轉行、連續日期數字實現方式及mybatis下實現方式OracleMyBatis
- 寫給前端工程師的Linux實戰教程【持續更新】前端工程師Linux
- 許可權處理 - 用redis實現分散式session~ (cookie && session )Redis分散式SessionCookie
- 專案實戰:閒話支付與轉賬
- SSH遠端埠轉發實戰詳解
- 通過redis實現session共享RedisSession
- 電商業務測試方案與實戰落地 (轉轉) - 田西西
- springboot註解實現非同步呼叫時no bean of type TaskExecutor and no bean named 'taskExecutor' eitherSpring Boot非同步Bean