日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

轉(zhuǎn)貼-JBuilder7+WebLogic7存取SQL Server2000( 二 )


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 = lineres.getString("notes") "n";
jTextArea1.setText(line);
con.close();
}
catch (Exception ex)
{
jTextArea1.setText("error : " ex.getMessage());
}
運行WebLogic7,運行程序單擊第一個按鈕使用JDBC直接連接SQLServer并獲取數(shù)據(jù),單擊第二個按鈕使用DataSource連接SQLServer并獲取數(shù)據(jù) 。
實戰(zhàn)2:Session Bean
建立一個簡單的Bean:
1. 關(guān)閉所有工程:File->Close Projects
2. 選擇File->New project
在Name欄中輸入HelloDemo,Directory欄中輸入存放路徑(不要有空格),其他不變,單擊Finish 。
3. 選擇File->New->Enterprise->EJB 2.0 Designer單擊OK 。
在彈出的對話框中單擊new建立一個Moudle,在Name中輸入HelloMoudle單擊OK關(guān)閉當(dāng)前對話框,再次單擊OK關(guān)閉對話框 。
4. 在右側(cè)的工作區(qū)中單擊右鍵選擇:Create EJB->Session Bean,將Bean Name改為HelloBean
5. 右鍵單擊代表HelloBean的長方形,選擇Add->Method
按如下填寫:
Method Name = SayHello
Return Type = java.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關(guān)閉當(dāng)前對話框,單擊OK開始編譯運行 。運行起來之后在左上角的目錄樹中右鍵單擊HelloModule選擇:Deploy options for “HelloModule.jar->Deploy來發(fā)布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 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運行 。Java, java, J2SE, j2se, J2EE, j2ee, J2ME, j2me, ejb, ejb3, JBOSS, jboss, spring, hibernate, jdo, struts, webwork, ajax, AJAX, mysql, MySQL, Oracle, Weblogic, Websphere, scjp, scjd JBuilde

推薦閱讀