|
Last-modified: 2003-12-15 (月) 15:48:50 (7449d)
フリーで使えるEJBコンテナ「JBoss」のセットアップから動作テストまでをレポートしました。Version3から、なかなか好いようです。機能がたくさんあって、楽しいですね。 -2002.10.18 インストールする
JBoss環境変数の設定(一応、念のため)
動作確認
<!-- EJB Reference --> <ejb-ref> <description>Example EJB Reference</description> <ejb-ref-name>ejb/Account</ejb-ref-name> <ejb-ref-type>Entity</ejb-ref-type> <home>com.mycompany.mypackage.AccountHome</home> <remote>com.mycompany.mypackage.Account</remote> </ejb-ref> <!-- Local EJB Reference --> <ejb-local-ref> <description>Example Local EJB Reference</description> <ejb-ref-name>ejb/ProcessOrder</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>com.mycompany.mypackage.ProcessOrderHome</local-home> <local>com.mycompany.mypackage.ProcessOrder</local> </ejb-local-ref>
MySQLとのJDBC接続設定
<mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=MySqlDS"> <attribute name="JndiName">MySqlDS</attribute> <attribute name="ManagedConnectionFactoryProperties"> <properties> <config-property name="ConnectionURL" type="java.lang.String">jdbc:mysql://{hostname}:3306/{dbname}</config-property> <config-property name="DriverClass" type="java.lang.String">org.gjt.mm.mysql.Driver</config-property> <!--set these only if you want only default logins, not through JAAS --> <config-property name="UserName" type="java.lang.String">{username}</config-property> <config-property name="Password" type="java.lang.String">{password}</config-property> </properties> </attribute> <!--Below here are advanced properties --> <!--hack--> <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper</depends> </mbean>
Context ctx = new InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:/MySqlDS"); java.sql.Connection con = ds.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("SELECT value FROM t1 WHERE id = " + id.intValue()); String retStr = null; while (rs.next()) { retStr = rs.getString("value"); } return retStr; <<おまけ>>
|