| 订阅 | 在线投稿
分享
 
 
 

JBuilder7+Weblogic7+mysql开发EJB配置

来源:互联网  宽屏版  评论
2008-06-01 03:09:17

本文为【JBuilder7+Weblogic7+mysql开发EJB配置】的汉字拼音对照版显示拼音

JBuilder7+Weblogic7+mysql kaifaEJBdepeizhi

peizhiJB+WLSkeyishuoshiyichangemengwangshangsoulesuoyoukeyisoudaodetieziyouzhiliangdebuguosansigekeyishuozhejige

tiezizaimouxiefangmianxiedequeshibucuobizheyeshikaotamendebangzhujingguojitianjiankudemosuocaiwanquanchenggongdizhengheleJB7+WLS7yi

jiMYSQLshujukulaikaifaEJBdedanzhejigetiezidoushiyiqiandeJB4-6WLS5-61deqingkuangxiaxiedeyouhenduoxuanxiangdoubushiyong

yuJB7+WLS7erqiedoushidanfangmiandemeiyouyigecongpeizhidaobushudewanzhengdewendang

yianzhuangbushuole

erpeizhianzhuanghaoJB7heWLS7houyinggaixianpeizhiWLS7yinweiWLS7peizhishiheJB7wuguanerJB7yaoxuanzeWLSdehuanjing

xiamiananshunxulaiyibubushuoming

wozaiwendangzhongyongdaodeliziziduanjiushiyongruziduannameyihouzaiyaoyongdaozhegeziduanjiuzhijiexiechengruhoudeziduan

peizhiMYSQLbiedeshujukudoushiyiyangdexinjianyigekumingruejbdb,peizhihaoyonghuminghemimaruroot,111111

bamysqldejdbc(rumysql.jar)fangdaoyigemuluzhongyibanfangzai%JAVA_HOME%/lib/xiabuguozhiyaobufangzairuanpanshang

zongshinengzhaodaode

peizhiWLS7

jiaruWLS7anzhuangzaic:\beaxiajinruc:\bea\weblogic700\binmuluxiugaistartWLS.cmd(zhuyishouxianxiugaizhege

wenjianshiyinweiyoudewendangshangshuoxiugaic:\bea\user_projects\mydomain\xiadestartWeblogic.cmdshibuduideshouxianxiu

gaizhegewenjianshizheshic:\bea\user_projects\mydomain\xiadestartWeblogic.cmdhuanmeiyouchanshengbaozhengnibuhuigaicuoru

guoshilinuxxiaxiugaistartWLS.sh

zhaodaoset CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;

%WL_HOME%\server\lib\weblogic.jar;%CLASSPATH%

jiashangmysql.jarcheng

set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;

%WL_HOME%\server\lib\weblogic.jar;path\mysql.jar;%CLASSPATH%

cundang退tuichuzaiqidongcaidanshangyunxingBEA Weblogic platform 7.0 -> domain configuration wizardyoudejiujiao

configuration wizard

1.Select a template:xuanzeWLS DomainNamemorendemydomain

2.Choose Server Type: diyige

3.Specify directory for "mydomain" domain:C:\bea\user_projects\

4.value Administrative Server Info-Admin Server Name or IP xiejiqideipzheyangbaoxianqitamoren

5.Configure Managed Server: Server Name:morenweimyserver

Server Listen Address:xiejiqideip .qitamoren

6.Create System UserName and Password:xieyonghuminghemima,ru:system:aaaaaa

7.Install Server as Windows Servic:zheliwenyaobuyaozaiqidongcaozuoxitongshiqidongkegenjuzijidexuyongxuanze

8.Install Domain in Windows Start Menu:zheliwenyaobuyaozaikaishicaidantianjiakuaijiefangshijianyishiYes.

zheyangzaikaishicaidanzhonghuichuxianEBA Weblogic Platform 7.0->User projects-my domain->Start Server

ruguo8xuanzeleyesxianzaijiucongkaishi->EBA Weblogic Platform 7.0->User projects-my domain->Start Serverqidong

dengyihuierqidongjieshuhoujinruhttp://localhost:7001/consoleruguozhaobudaoyemianbalocalhosthuanchengzhujiminghuoIPshishi

ruguobunengjinrujianchashangmiandebuzhoufanzhengzheliruguobuneng访fangwenxiangxiazuolesiyeyaogeiwo访fangwendaozhegeyemian

shurugangcaideyonghuminghemima(system:aaaaaa)jinru

zaizuobiandemulushuzhongxuanzhongServices->JDBC->Connection PoolsdanjiyoucedeConfigure a new JDBC Connection Pool.

shuruyixiaxinxi

Configuration->Generalye

Name = Mysql Connection Pool

URL = jdbc:mysql://localhost:3306/ejbdb(zhuyiejbdbshiwoshangmiandeliziziduanyixiadouhuizheyang)

Driver classname = org.gjt.mm.mysql.Driver

Properties :

user=root

password=111111 zheliangxingshiProperties deneirongjiushiname=valuexingshi

danjiCreatejianlilianjiechi

xuanzeTargets->Serverye

jiangmyserver(fuwuqimingcheng)yizhiyoucedeliebiaozhongdanjidanjiApply

zaizuobiandemulushuzhongxuanzhongServices->JDBC->Data SourceshuozheTXData SourcesdanjiyoucedeConfigure a new JDBC

Connection Pool.shuruyixiaxinxi

Configuration->Generalye

Name = Mysql Tx Data Source

JNDI Name = ejbPool zhegemingzijiushiniyihouyaoyinyongdeDataSourcemingcheng

Pool Name = Mysql Connection Pool

xuanzhongEmulate Two-Phase Commit for non-XA DriverheRow Prefetch Enabled

danjiCreatejianlishujuyuan

Targets->Serverye

jiangmyserver(fuwuqimingcheng)yizhiyoucedeliebiaozhongdanjidanjiApplypeizhiwanbi

-----------------------------------------------------------------------------------------------------

peizhiJB7

1. xiugaihuanjingbianliangTEMPheTMP weibudaikonggedemuluruc:\winnt\temp,yidingyaozhuyiburanfabukendingbuchenggong

2. qidongJbuilder7Tools->Configure libraries->class->Add,zhaodaomysql.jarOKOK

3.xuanzeTools->Configure ServersxuanzhongzuocedeWeblogic Application Server 6.x+xuanzhongyoubiande

Enable Server

4. jiangGeneral->Home DirectorysheweiWebLogic7deHome Directoryruc:/bea/weblogic700/serverzhengchang

dehuaJbuilder7jiangzidongweinitianhaoqitadexiangserver parametersbutianzaixiamiandeclasszhongyongaddjiashangmysql.jarmorenyijing

jiashanglec:/bea/weblogin700/server/lib/weblogic.jarhec:/bea/weblogin700/server/lib/weblogic_sp.jarruguo

meiyoushuomingc:/bea/weblogic700/servermeiyouzhidingzhengqueqishic:/bea/weblogin700/server/lib/weblogic_sp.jarshibucun

zaidebuyaoguantazhiyaobamysql.jarjiajinlairuguo2meiyouzuoshizhaobudaode

5. jiangCustom->JDK Installation Directoryshewei JDKdeanzhuangmuluruc:/bea/jdk131_02

6. jiangCustom->BEA Home DirectorysheweiWebLogic7deHome Director,ruc:/bea

7. jiangCustom->Domain Directorysheweinideyumuluruc:/bea/user_projects/mydomain

8. tianhaoUser name, Password ,Domain name, Server namehoudanjiOK退tuichu

9. xuanzeTools->Enterprise SetupdanjiCORBAyeshangdeNew, anxiabiaotianxiexiangyingxinxi

Name for this configuration = WelLogic

Path for ORB Tools = c:/bea/weblogic700/server

Library for Projects = WebLogic 6.x+ Deploy

IDL compiler command = idlj.exe

Commnad option for output directory = c:\temp(renyimulubuyaoyoukongge)

danjiOK退tuichu

10.config JDKSzhongzuihaobaochiyongjb7zijideJDK131huoyongEABxiamiandeJDKbuyaogaichenglingwaianzhuangdeJDK14yinwei

zhegebanbenzhongyouyixiebendifangfashixianbunengheWLShenhaodigongzuokendinghuichucuo

11xuanzeProject->Default Project properties zaiPathyedeRequired librarieszhongjianghuikandaoWebLogic 6.x+

ClientheWebLogic 6.x+ DeployliangxiangruguomeiyouqingjianchayishangbuzhoushifouzhengquexuanzeServeryedanjiSingle services

for all service in projectzaixialaliebiaozhongxuanzeWebLogic Application Server 6.x+danjiOK退tuichu

12Tools->Database pilot->view->options->Drivers->Addtanchuduihuakuangzhongshuruorg.gjt.mm.mysql.Driver

quedinghouzaixiamiandeSimple URLzhongshurumysql://localhost:3306/ejbDBzhuyiqianmianmeiyou"jdbc:"queding.

zaiFile->Newtanchunew URL,xuanzeDriverweigangcaijiarudeorg.gjt.mm.mysql.Driver,zeURLzidongweixianshiwei

jdbc:mysql://localhost:3306/ejbDB,quedingranhoudianzhonggongjutiaonagexiangyouxiadejiantouapplyshuangjizuobiangangjiarudezhege

shuruyonghumingroothemima111111keshiceshishujukulianjieshifoutongguoruguomeiyoukandaoxiamiandebiaoqingjianchayishangbuzhou

---------------------------------------------------------------------------------------------------------

kaifaEJB

File->New Projectshengchengyigexingongchengru:myproject

File->New xuanzeEnterprise,xuanzeEJB2.0 Bean DesignerOK

anNewtanchuEJB module WizardNamegaiweiAccountApp,zuobianzushushangchuxianshejiqiAccountApp,diankaiqianmiandejiahaokeyi

kandaotaxiamianyouJDBC 1 DatasourcesheSecurity RolesshuangjiEJBshejiqiAccountAppyoubianxianshishejijiemianyihoucongbiedejiemian

yaofanhuishejijiemianjiushuangjishejiqidianjigongjutiaoshangdiyigetubiaojiushixiangyigeguziyiyangdedong西xishangmianyouyigetaiyangletitlewei

Create EJB.yousigexuanxiangCMP2.0,BMP,SESSION,MESSAGEp sizhongBEANbenlixuanBMPchulaiBeanshejichuangyoubianhuiyouyige

Bean propertieskuangbuguoruguoniMOUSEdongdekuaitakenenghuixiaoshilebuyaojinzaiBEANdemingzishangzuojihuichulaibaBEANdemingzigaiwei

AccountBean,interfaceweilocal/remotealway warp primary keyweitrue,dianjiclasses and package

package:gaiweinixiangyaofangdebaomingbenliwei:com.fuck.axamn

ruguoniyongmorenleimingyexingdanwoxihuanyuanchengjiekouzhongbujiaRemote,erlocaljiekouzhongjialocalerJBzhenghaoxiangfantashizheyangde

Bean class: com.fuck.axamn.AccountBean

Home interface class: com.fuck.axamn.AccountRemoteHome

local Home interface class: com.fuck.axamn.AccountHome

Remote interface calss: com.fuck.axamn.AccountRemote

Local interface calss: com.fuck.axamn.Account

erbenlizhongwoshizheyangmingmingde

Bean class: com.fuck.axamn.AccountBean

Home interface class: com.fuck.axamn.AccountHome

local Home interface class: com.fuck.axamn.AccountLocalHome

Remote interface calss: com.fuck.axamn.Account

Local interface calss: com.fuck.axamn.AccountLocal

youjiBeanshejichuangshangBEANdemingzixuanview source,haobabalizishougongqiaoshangquxianbuyaoCOPYshangquazijiqiaokeyijiashenlijieru

guozuihoulechucuolezaiCOPY

Beanleibenshenshejihaohoudianjizuobianshejiqishangmiandepackagelimianhuikandaotadejiekouleiyigeyigedianjiyoubianhuichuxianyuanmayigeyige

shejihaoyaojiarudefushuleibirubenlizhongdeAccountExeptiontongguoyoujipackagexuanAdd files/packagesjiaruyigejavawenjian

zhuyiyaohezidongshengchengdewenjianzaitongyimulu

quanbuxiehaohouyoujigongchengmingmakeyixiaranhouanF9yunxingruguoWLSmeiyouqidongJBhuizidongqidongtade

meiyouwentihouyoujishejiqixuanzeDeploykeyishunlifabudaoWLSshangconghttp://localhost:7001/consolejinruhoukeyikandaoAccountApp

beifabudaoWLSzhongle

---------------------------------------------------------------------------------------------------------------

ceshi:

zaigongchengzhong,File->New->Enterprise->EJB test Client.mingchengsheweiAccountClient

zaizuobianzujianshuzhongshuangjiAccountClient.java,bianjineirongweibenbenlitigongdeneirong.

mysql -uroot -p

111111

use ejbdb;

create table accounts (id varchar(60) not null primary key,ownerName varchar(60),double balance(8,2) default 0.00);

make AccountClient.java

run AccountClient.java

____________________________________________________________________

JB7+WLS7+MYSQL kaifaCMP

CMPkaifaqishibiBMPgengjiandan(woshuodeshicaozuoshangdejiandan),zhiyaodingyihaonideyewuluoji,

zaishixianshiqishihenkuaide.danwangshangjingranzhaobudaoyirenheyongJBkaifaCMPdelizi,zaiJdaoshangyouyipianwenzhang

jingranyaoshou50yuancaijiaodajiaruheyongJBkaifaCMP,taiheile.erqieshizhanchangfade,suoyizaixiabuganzainaer

fabiaozhepianwenzhang,buguoqingdajiazaibiededifangxianghuzhuantie,buyaorangnajiahuoheilexinpianbierendeqian.

JBkaifaCMP,qishifang便biandehen,jiushidaduoshurenbuzhidaoruhecaozuo,yinweiCMPbushicongBEANshejiqi

deshejijiemianjianlide.erqiehenduoxuanxiangmeiyoubierenshuomingqueshibuzhidaoxuanshenme.

qiantishigenjuyuanlaidenayipianpeizhidewenzhangyijingpeizhihaoJB7+WLS+MYSQL

xianzaikaishi,xiandingyiCMPchijiuhuaziduandeshujuku,biruwomenyaozuoyigeProductdeBEAN,baokuosi

geziduan:

productID:chanpinbianhao(weiyi)

name:chanpinmingcheng

description:chanpinshuoming

basePrice:chanpinjijia

namexianyaodingyihaoshujuku:

mysql -uroot -p

111111

use ejbdb;

create table ProductBean(

productID varchar(60) not null primary key,

name varchar(60),

description varchar(200),

basePrice double(8,2) default 0.00

);

qidongJB7.

File->New Project->shurugongchengming ru:myproject2

File->New xuanzeEnterprise,xuanzeEJB2.0 Bean DesignerOK

anNewtanchuEJB module WizardNamegaiweiProductApp,zuobianzushushangchuxianshejiqiProductApp

zhuyizheshibuyaocongyoubiandeshejijiemianshangCreate EJB,shuangjishejiqiProductApp,zaizujianshuxiamianhuichuxian

DataSources,youjianxuanze Import Schema From Database,tanchuDatabase Schema providerchuangkou

zaiAll schemaqianmiandagou.

xuanzeDriverwei org.gjt.mm.mysql.Driver,xiamiandeurlhuizidongweiniyuanlaishedingdeURL.zhuyizai

yuanlaishedingURLshibuyinggaijiajdbc:,yaobuzheerjiuhuichuxianjdbc:jdbc:mysql://localhost:3306/ejbdb

ruguoshizheyangqudiaoyige"jdbc:",shuruusernamehepassword(root:111111).bajdni namezhongdemoren

zhiDataSourcegaiweinizaiWLSzhongpeizhiMYSQLshideJDIN NAME(lizizhongshiejbPool).dianjiOK,ruguolianjie

chenggongzaiDataSourcesxiamianhuichuxianyigeejbPool,dianjitaqianmiande+haokeyikandaoejbdbzhegekuxiamiandesuo

youbiao,womenxianzaiyaobaproductbeanzhegebiaolaizuoweichijiuhuaziduandeduiyingguanxi,suoyiyoujiproductbean

xuanbadiyixiangCreate CMP2.0 Entity Bean.zhuyiMysqlbabiaomingquanbusheweixiaoxiele,suoyixinjiandeBean

demingchengweiProductbean,zheshiyoubiandeshejijiemianzhongchanshengyigeBeanshejichuang,mingchengweiProductbean,zuoji

mingcheng,youbianchuxianshuxingduihuakuang:

Bean name:gaiweiProductBean.

Abstract Schema name:huizidonggenzhegaichengProductBean.

interface:local/remote

always wrap primary key:true

classes and packages:huanshideBMPyiyang,morendemingmingshi:

Bean class: com.fuck.axamn.ProductBean

Home interface class: com.fuck.axamn.ProductRemoteHome

local Home interface class: com.fuck.axamn.ProductHome

Remote interface calss: com.fuck.axamn.ProductRemote

Local interface calss: com.fuck.axamn.Product

erbenlizhongwoshizheyangmingmingde

Bean class: com.fuck.axamn.ProductBean

Home interface class: com.fuck.axamn.ProductHome

local Home interface class: com.fuck.axamn.ProductLocalHome

Remote interface calss: com.fuck.axamn.Product

Local interface calss: com.fuck.axamn.ProductLocal

CMP propertieszhong,benlishiyigeBEANduiyingyizhangbiao,suoyixiandiyigeSingle table maping

ruguoshiyigeBEANheduobiaoguanguanlianxuandierxiang,ranhoubazuobiandeprimary keyheyoubiangebiaoduiyingdeziduan

yonghong线xianlianyixiajiuxingle,nizhiyaodianprimary keydeziduantuojiuhuichuxianhong线xian.

dianjizuobianzujianshushangshejiqiProductAppshangmiandepackage,yijiyijidiankai,kandaoshengchengde5gewenjian

ProductHome.java

ProductLocalHome.java

Product.java

ProductLocal.java

ProductBean.java

yiyianbenlifujianzhongdewenjianneirongqiaojinqu.wanchenghoushuangjishejiqi,rangyoubianhuidaoBEANshejijiemianshang,huikan

daoProductBeandefinderfangfayouqige,findByPrimaryKeyshixitongzidongshengchengxitongde,zhegebuyaonikaolv.

danshiqitade6gexitongbukenengzhidaonishianshenmetiaojianchazhao,suoyiyaoshougongxieruEJB-QL.

zaigefangfashangdianjiyixiajiuhuizaiyoubiantanchuduihuakuang,bieyoudoubudong,zaizuixiamiandeQueryneirongkuangzhongshuruyi

xiaduiyingdeneirong

findByNamefangfa:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.name=?1

findByDescriptionfangfa:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.description=?1

findByBasePricefangfa:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePrice=?1

findExpensiveProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePricefindCheapProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePrice>?1

findAllProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.productID IS NOT NULL

youjiandianjigongchengmysproject make,ruguoshurumeiyoucuowu,yinggaishunlibianyi.ranhouanF9yunxingruguoWLSmeiyouqidongJB

huizidongqidongtade

meiyouwentihouyoujishejiqixuanzeDeploykeyishunlifabudaoWLSshangconghttp://localhost:7001/consolejinru

houkeyikandaoProductApp beifabudaoWLSzhongle

------------------------------------------------------------------------------------------

ceshi:

zaigongchengzhong,File->New->Enterprise->EJB test Client.mingchengsheweiProductClient

zaizuobianzujianshuzhongshuangjiProductClient .java,bianjineirongweibenbenlitigongdeneirong.

make ProductClient.java

run ProductClient.java

zaiceshiwenjianzhongruhechazhaoProductAppzhegeEJBne,qishinizaizuobianzujianshuzhongshuangjishejiqixiamianProductBeande

mingcheng,youbianhuixianshichuzhegeBEANdeshuxing,Home JDNI NAMEheLocal JDNI namefenbiejiushiyuanchenghebendideJDNI

mingcheng,nizaiceshiwenjianjiuchazhaozhegemingcheng,ru:

Object objref = ctx.lookup("ProductBeanRemote");

"ProductBeanRemote"jiushiHome JDNI NAMEkuangzhongdezhi.

原文
 
JBuilder7+Weblogic7+mysql 开发EJB的配置 配置JB+WLS可以说是一场恶梦,网上搜了所有可以搜到的贴子,有质量的不过三四个,可以说这几个 贴子在某些方面写得确实不错,笔者也是靠它们的帮助,经过几天艰苦的摸索才完全成功地整合了JB7+WLS7以 及MYSQL数据库来开发EJB的。但这几个贴子都是以前的JB4-6,WLS5-6。1的情况下写的,有很多选项都不适用 于JB7+WLS7,而且都是单方面的,没有一个从配置到布署的完整的文档。 一、安装不说了。 二、配置:安装好JB7和WLS7后,应该先配置WLS7,因为WLS7配置时和JB7无关而JB7要选择WLS的环境 下面按顺序来一步步说明: 我在文档中用到的例子字段(就是用“如:字段”),那么以后在要用到这个字段就直接写成如后的字段 配置MYSQL(别的数据库都是一样的)新建一个库名,如:ejbdb,配置好用户名和密码如(root,111111) 把mysql的jdbc(如mysql.jar)放到一个目录中,一般放在%JAVA_HOME%/lib/下。不过只要不放在软盘上 总是能找到的。 配置WLS7 假如WLS7安装在c:\bea下,进入c:\bea\weblogic700\bin目录,修改startWLS.cmd(注意首先修改这个 文件是因为有的文档上说修改c:\bea\user_projects\mydomain\下的startWeblogic.cmd,是不对的。)首先修 改这个文件是这时c:\bea\user_projects\mydomain\下的startWeblogic.cmd还没有产生,保证你不会改错。如 果是linux下修改startWLS.sh 找到set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar; %WL_HOME%\server\lib\weblogic.jar;%CLASSPATH% 加上mysql.jar:成 set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar; %WL_HOME%\server\lib\weblogic.jar;path\mysql.jar;%CLASSPATH% 存档退出,在启动菜单上运行BEA Weblogic platform 7.0 -> domain configuration wizard有的就叫 configuration wizard。 1.Select a template:选择WLS Domain,Name默认的mydomain 2.Choose Server Type: 第一个 3.Specify directory for "mydomain" domain:C:\bea\user_projects\ 4.value Administrative Server Info-Admin Server Name or IP 写机器的ip,这样保险,其它默认 5.Configure Managed Server: Server Name:默认为myserver Server Listen Address:写机器的ip .其它默认 6.Create System UserName and Password:写用户名和密码,如:system:aaaaaa 7.Install Server as Windows Servic:这里问要不要在启动操作系统时启动,可根据自己的需用选择。 8.Install Domain in Windows Start Menu:这里问要不要在开始菜单添加快捷方式,建议是“Yes”. 这样在开始菜单中会出现EBA Weblogic Platform 7.0->User projects-my domain->Start Server 如果8选择了yes,现在就从开始->EBA Weblogic Platform 7.0->User projects-my domain->Start Server启动 等一会儿,启动结束后进入:http://localhost:7001/console如果找不到页面把localhost换成主机名或IP试试 如果不能进入检查上面的步骤,反正这里如果不能访问向下做了,死也要给我访问到这个页面。 输入刚才的用户名和密码(system:aaaaaa)进入。 在左边的目录树中选中Services->JDBC->Connection Pools,单击右侧的Configure a new JDBC Connection Pool. 输入以下信息: Configuration->General页: Name = Mysql Connection Pool URL = jdbc:mysql://localhost:3306/ejbdb(注意ejbdb是我上面的例子字段,以下都会这样) Driver classname = org.gjt.mm.mysql.Driver Properties : user=root password=111111 这两行是Properties 的内容,就是name=value形式 单击Create建立连接池。 选择Targets->Server页: 将myserver(服务器名称)移至右侧的列表中,但击单击Apply 在左边的目录树中选中Services->JDBC->Data Sources(或者TXData Sources)单击右侧的Configure a new JDBC Connection Pool.,输入以下信息: Configuration->General页: Name = Mysql Tx Data Source JNDI Name = ejbPool 这个名字就是你以后要引用的DataSource名称 Pool Name = Mysql Connection Pool 选中Emulate Two-Phase Commit for non-XA Driver和Row Prefetch Enabled 单击Create建立数据源。 Targets->Server页: 将myserver(服务器名称)移至右侧的列表中,但击单击Apply,配置完毕 ----------------------------------------------------------------------------------------------------- 配置JB7 1. 修改环境变量TEMP和TMP 为不带空格的目录如:c:\winnt\temp,一定要注意,不然发布肯定不成功 2. 启动Jbuilder7,Tools->Configure libraries->class->Add,找到mysql.jar,OK,OK 3.选择:Tools->Configure Servers选中左侧的Weblogic Application Server 6.x+,选中右边的 Enable Server 4. 将General->Home Directory设为WebLogic7的Home Directory如:c:/bea/weblogic700/server,正常 的话Jbuilder7将自动为你添好其他的项。server parameters不填,在下面的class中用add加上mysql.jar默认已经 加上了c:/bea/weblogin700/server/lib/weblogic.jar和c:/bea/weblogin700/server/lib/weblogic_sp.jar,如果 没有说明c:/bea/weblogic700/server没有指定正确。其实c:/bea/weblogin700/server/lib/weblogic_sp.jar是不存 在的,不要管它。只要把mysql.jar加进来。如果2没有做,是找不到的。 5. 将Custom->JDK Installation Directory设为 JDK的安装目录,如:c:/bea/jdk131_02 6. 将Custom->BEA Home Directory设为WebLogic7的Home Director,如:c:/bea 7. 将Custom->Domain Directory设为你的域目录,如:c:/bea/user_projects/mydomain 8. 添好User name, Password ,Domain name, Server name后,单击OK退出。 9. 选择:Tools->Enterprise Setup,单击CORBA页上的New, 按下表填写相应信息: Name for this configuration = WelLogic Path for ORB Tools = c:/bea/weblogic700/server Library for Projects = WebLogic 6.x+ Deploy IDL compiler command = idlj.exe Commnad option for output directory = c:\temp(任意目录,不要有空格) 单击OK退出。 10.config JDKS中最好保持用jb7自己的JDK1。3。1或用EAB下面的JDK,不要改成另外安装的JDK1。4,因为 这个版本中有一些本地方法实现不能和WLS很好地工作,肯定会出错。 11.选择Project->Default Project properties 在Path页的Required libraries中将会看到WebLogic 6.x+ Client和WebLogic 6.x+ Deploy两项,如果没有,请检查以上步骤是否正确。选择Server页,单击Single services for all service in project,在下拉列表中选择WebLogic Application Server 6.x+,但击OK退出。 12。Tools->Database pilot->view->options->Drivers->Add,弹出对话框中输入org.gjt.mm.mysql.Driver 确定后在下面的Simple URL中输入mysql://localhost:3306/ejbDB,注意前面没有"jdbc:"确定. 在File->New弹出new URL,选择Driver为刚才加入的org.gjt.mm.mysql.Driver,则URL自动为显示为 jdbc:mysql://localhost:3306/ejbDB,确定,然后点中工具条那个向右下的箭头(apply)。双击左边刚加入的这个, 输入用户名root和密码111111可是测试数据库连结是否通过,如果没有看到下面的表请检查以上步骤。 --------------------------------------------------------------------------------------------------------- 开发EJB File->New Project生成一个新工程;如:myproject File->New 选择Enterprise,选择EJB2.0 Bean Designer,OK。 按New弹出EJB module Wizard,Name改为AccountApp,左边组树上出现设计器AccountApp,点开前面的加号可以 看到它下面有JDBC 1 Datasources和Security Roles。双击EJB设计器AccountApp,右边显示设计界面,以后从别的介面 要返回设计界面就双击设计器。点击工具条上第一个图标,就是象一个谷子一样的东西上面有一个太阳了,title为 Create EJB.有四个选项,CMP2.0,BMP,SESSION,MESSAGEp 四种BEAN,本例选BMP,出来Bean设计窗,右边会有一个 Bean properties框,不过如果你MOUSE动得快它可能会消失了。不要紧,在BEAN的名字上左击会出来,把BEAN的名字改为 AccountBean,interface为local/remote。alway warp primary key为true,点击classes and package: package:改为你想要放的包名,本例为:com.fuck.axamn 如果你用默认类名也行,但我喜欢远程接口中不加Remote,而local接口中加local,而JB正好相反,它是这样的。 Bean class: com.fuck.axamn.AccountBean Home interface class: com.fuck.axamn.AccountRemoteHome local Home interface class: com.fuck.axamn.AccountHome Remote interface calss: com.fuck.axamn.AccountRemote Local interface calss: com.fuck.axamn.Account 而本例中我是这样命名的: Bean class: com.fuck.axamn.AccountBean Home interface class: com.fuck.axamn.AccountHome local Home interface class: com.fuck.axamn.AccountLocalHome Remote interface calss: com.fuck.axamn.Account Local interface calss: com.fuck.axamn.AccountLocal 右击Bean设计窗上BEAN的名字,选view source,好吧,把例子手工敲上去。先不要COPY上去啊,自己敲可以加深理解。如 果最后了出错了再COPY。 Bean类本身设计好后,点击左边设计器上面的package里面会看到它的接口类,一个一个点击右边会出现源码,一个一个 设计好,要加入的附属类(比如本例中的AccountExeption)通过右击package,选Add files/packages,加入一个java文件, 注意要和自动生成的文件在同一目录。 全部写好后,右击工程名,make一下,然后按F9运行。如果WLS没有启动JB会自动启动它的。 没有问题后右击设计器,选择Deploy可以顺利发布到WLS上,从http://localhost:7001/console进入后可以看到AccountApp 被发布到WLS中了。 --------------------------------------------------------------------------------------------------------------- 测试: 在工程中,File->New->Enterprise->EJB test Client.名称设为AccountClient 在左边组件树中双击AccountClient.java,编辑内容为本本例提供的内容. mysql -uroot -p 111111 use ejbdb; create table accounts (id varchar(60) not null primary key,ownerName varchar(60),double balance(8,2) default 0.00); make AccountClient.java run AccountClient.java ____________________________________________________________________ JB7+WLS7+MYSQL 开发CMP CMP开发其实比BMP更简单(我说的是操作上的简单),只要定义好你的业务逻辑, 在实现时其实很快的.但网上竟然找不到一任何用JB开发CMP的例子,在J道上有一篇文章 竟然要收50元才教大家如何用JB开发CMP,太黑了.而且是站长发的,所以在下不敢在那儿 发表这篇文章,不过请大家在别的地方相互转贴,不要让那家伙黑了心骗别人的钱. JB开发CMP,其实方便得很,就是大多数人不知道如何操作,因为CMP不是从BEAN设计器 的设计界面建立的.而且很多选项没有别人说明确实不知道选什么. 前题是根据原来的那一篇配置的文章已经配置好JB7+WLS+MYSQL 现在开始,先定义CMP持久化字段的数据库,比如我们要做一个Product的BEAN,包括四 个字段: productID:产品编号(唯一) name:产品名称 description:产品说明 basePrice:产品基价 那么先要定义好数据库: mysql -uroot -p 111111 use ejbdb; create table ProductBean( productID varchar(60) not null primary key, name varchar(60), description varchar(200), basePrice double(8,2) default 0.00 ); 启动JB7. File->New Project->输入工程名 如:myproject2 File->New 选择Enterprise,选择EJB2.0 Bean Designer,OK。 按New弹出EJB module Wizard,Name改为ProductApp,左边组树上出现设计器ProductApp 注意这时不要从右边的设计界面上Create EJB,双击设计器ProductApp,在组件树下面会出现 DataSources,右键选择 Import Schema From Database,弹出Database Schema provider窗口 在All schema前面打勾. 选择Driver为 org.gjt.mm.mysql.Driver,下面的url会自动为你原来设定的URL.注意在 原来设定URL时不应该加jdbc:,要不这儿就会出现jdbc:jdbc:mysql://localhost:3306/ejbdb 如果是这样去掉一个"jdbc:",输入username和password(root:111111).把jdni name中的默认 值DataSource改为你在WLS中配置MYSQL时的JDIN NAME(例子中是ejbPool).点击OK,如果连结 成功在DataSources下面会出现一个ejbPool,点击它前面的+号可以看到ejbdb这个库下面的所 有表,我们现在要把productbean这个表来作为持久化字段的对应关系,所以右击productbean 选把第一项Create CMP2.0 Entity Bean.注意Mysql把表名全部设为小写了,所以新建的Bean 的名称为Productbean,这时右边的设计界面中产生一个Bean设计窗,名称为Productbean,左击 名称,右边出现属性对话框: Bean name:改为ProductBean. Abstract Schema name:会自动跟着改成ProductBean. interface:local/remote always wrap primary key:true classes and packages:还是的BMP一样,默认的命名是: Bean class: com.fuck.axamn.ProductBean Home interface class: com.fuck.axamn.ProductRemoteHome local Home interface class: com.fuck.axamn.ProductHome Remote interface calss: com.fuck.axamn.ProductRemote Local interface calss: com.fuck.axamn.Product 而本例中我是这样命名的: Bean class: com.fuck.axamn.ProductBean Home interface class: com.fuck.axamn.ProductHome local Home interface class: com.fuck.axamn.ProductLocalHome Remote interface calss: com.fuck.axamn.Product Local interface calss: com.fuck.axamn.ProductLocal CMP properties中,本例是一个BEAN对应一张表,所以先第一个Single table maping 如果是一个BEAN和多表关关联选第二项,然后把左边的primary key和右边各表对应的字段 用红线连一下就行了,你只要点primary key的字段拖就会出现红线. 点击左边组件树上设计器ProductApp上面的package,一级一级点开,看到生成的5个文件 ProductHome.java ProductLocalHome.java Product.java ProductLocal.java ProductBean.java 一一按本例附件中的文件内容敲进去.完成后双击设计器,让右边回到BEAN设计界面上,会看 到ProductBean的finder方法有七个,findByPrimaryKey是系统自动生成系统的,这个不要你考虑. 但是其它的6个系统不可能知道你是按什么条件查找,所以要手工写入EJB-QL. 在各方法上点击一下就会在右边弹出对话框,别有都不动,在最下面的Query内容框中输入以 下对应的内容 findByName方法:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.name=?1 findByDescription方法:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.description=?1 findByBasePrice方法:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePrice=?1 findExpensiveProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePricefindCheapProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.basePrice>?1 findAllProducts:SELECT OBJECT(p) FROM ProductBean AS p WHERE p.productID IS NOT NULL 右键点击工程mysproject make,如果输入没有错误,应该顺利编译.然后按F9运行。如果WLS没有启动JB 会自动启动它的。 没有问题后右击设计器,选择Deploy可以顺利发布到WLS上,从http://localhost:7001/console进入 后可以看到ProductApp 被发布到WLS中了。 ------------------------------------------------------------------------------------------ 测试: 在工程中,File->New->Enterprise->EJB test Client.名称设为ProductClient 在左边组件树中双击ProductClient .java,编辑内容为本本例提供的内容. make ProductClient.java run ProductClient.java 在测试文件中如何查找ProductApp这个EJB呢,其实你在左边组件树中双击设计器下面ProductBean的 名称,右边会显示出这个BEAN的属性,Home JDNI NAME和Local JDNI name分别就是远程和本地的JDNI 命称,你在测试文件就查找这个名称,如: Object objref = ctx.lookup("ProductBeanRemote"); "ProductBeanRemote"就是Home JDNI NAME框中的值.
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有