posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          ?引用:http://bbs.mysql.cn/thread-9135-1-2.html
          ?引用:21. 觸發程序

          delimiter?//
          create?trigger?a_bi
          before?
          insert?on?a
          for?each?row?Begin
          ????
          if?new.s2=0?then
          ??????
          if(new.s3=1)?then
          ????????
          insert?into?b(s2)?values(new.s1);
          ??????elseif(new.s3
          =2)then
          ????????
          insert?into?c(s2)?values(new.s1);
          ??????
          end?if;
          ????
          end?if;
          ????
          end;//
          delimiter?;

          posted @ 2008-01-24 18:26 G_G 閱讀(277) | 評論 (0)編輯 收藏

          討厭(370801149) 14:02:04 ☆づ(18246131) 14:02:45 web.xml,server.xml 討厭(370801149) 14:02:57 server.xml ☆づ(18246131) 14:02:58 這兩個地方,你都配置了嗎? 討厭(370801149) 14:03:01 en 討厭(370801149) 14:03:14 jdbc icijavax.sql.DataSourceContainer 討厭(370801149) 14:03:17 web.xml 討厭(370801149) 14:03:28 WEB-INF/web.xml 討厭(370801149) 14:03:33 context.xml

          posted @ 2008-01-24 14:12 G_G 閱讀(206) | 評論 (0)編輯 收藏

          1。存儲過程實現:
          引用:20.2.1. CREATE PROCEDURE和CREATE FUNCTION(mysql在線文檔)

          --test.sql

          DELIMITER?$$
          drop?procedure?if?exists?test.sproc?$$
          create?procedure?sproc(out?param1?int)
          begin
          ????
          select?count(*)?into?param1?from?account;
          end?$$
          DELIMITER?;

          命令 cmd-> mysql -u root test<c:\test.sql

          使用:
          mysql>?call?sproc(@a);
          Query?OK,?
          0?rows?affected?(0.00?sec)

          mysql
          >?select?@a?;
          +------+
          |?@a???|
          +------+
          |?1????|
          +------+
          1?row?in?set?(0.00?sec)



          posted @ 2008-01-22 17:58 G_G 閱讀(1559) | 評論 (0)編輯 收藏

          java 內連
          ??????????? //用 java jdk URL
          ??? ??? ??? URL?httpurl?
          =?new?URL(url);
          ????????????HttpURLConnection?httpConn?
          =?null;
          ????????????httpConn?
          =?(HttpURLConnection)?httpurl.openConnection();
          ????????????httpConn.setRequestMethod(
          "POST");
          ????????????httpConn.setDoOutput(
          true);
          ????????????httpConn.setDoInput(
          true);
          ??? ?? ?? ? //
          正式連接
          ????????????httpConn.getOutputStream();
          ??? ?? ???? /**輸入參數
          ??? ?? ?? ? PrintWriter outs = new PrintWriter(httpConn.getOutputStream());
          ??? ??? ??? outs.print("&back_url=" + returnurl);
          ??? ??? ??? outs.print("&orderid=" + deposit.getOrderId());
          ??? ??? ??? outs.print("&bussinessid=" + SZFConstant.B_ID);
          ??? ??? ??? outs.print("&digestString="
          ??? ??? ??? ??? ??? + MD5Util.MD5Encode(SZFConstant.B_ID + deposit.getOrderId()
          ??? ??? ??? ??? ??? ??? ??? + SZFConstant.KEY));
          ??? ??? ??? outs.flush();
          ??? ??? ??? outs.close();

          ??? ?? ?? ? GET 就不要 說 了? url + 參數
          ??????????? */

          ????????????
          byte[]?bb?=?new?byte[httpConn.getInputStream().available()];
          ????????????httpConn.getInputStream().read(bb);
          ??????????? //取得數據
          ??? ??? ??? String?str?
          =?new?String(bb);

          javascript 現在這種取法有個名字叫(ajax)(轉)

          <html>
          <head>
          <link?href="http://www.cc168.com.cn/css/index.css"?rel="stylesheet"?type="text/css">
          <link?rel="stylesheet"?href="http://www.cc168.com.cn/css/framework.css"?type="text/css"/>
          ?
          <script?language="javascript">
          ?
          ?window.onload?
          =?function()
          ?{
          ??CreateDateSelect();
          ?}

          ?
          var?xmlHttp?=?false;
          ?
          var?e;
          ?
          ?
          //創建XMLHTTP對象
          ?function?getXMLHTTPObj()
          ?{
          ??
          var?C?=?null;
          ??
          try
          ??{
          ?????C?
          =?new?ActiveXObject("Msxml2.XMLHTTP");
          ??}
          ??
          catch(e)
          ??{
          ???
          try
          ???{
          ????C?
          =?new?ActiveXObject("Microsoft.XMLHTTP");
          ???}
          ???
          catch(sc)
          ???{
          ????C?
          =?null;
          ???}
          ??}
          ??
          ??
          if(?!C?&&?typeof?XMLHttpRequest?!=?"undefined"?)
          ??{
          ???C?
          =?new?XMLHttpRequest();
          ??}
          ??
          ??
          return?C;
          ?}
          ?
          ?
          //調用遠程方法
          ?function?callServer(e)
          ?{?
          ??
          try
          ??{
          ???
          if(?xmlHttp?&&?xmlHttp?.readyState?!=?0?)
          ???{
          ????xmlHttp.abort();
          ???}
          ???
          ???xmlHttp?
          =?getXMLHTTPObj();
          ???
          ???
          if(?xmlHttp?)
          ???{
          ????document.getElementById(
          "outgroup").style.display?=?"none";
          ????
          //獲取查詢日期
          ????var?dateSele?=?e.options[e.selectedIndex].value;
          ????document.getElementById(
          "date").innerHTML?=?dateSele?+?"?開放式基金凈值";

          ????
          //構造查詢連接字符串
          ????var?url?=?"https://www.google.com/accounts/ManageAccount";
          ????
          ????
          //打開連接
          ???if(navigator.appName?==?'Netscape'){
          ???
          try?{
          ????netscape.security.PrivilegeManager.enablePrivilege(
          "UniversalBrowserRead");
          ???}?
          catch?(e)?{
          ???????alert(
          "Permission?UniversalBrowserRead?denied.");
          ???}}
          ????xmlHttp.open(
          "GET",?url,?true);
          ????
          //設置回調函數
          ????xmlHttp.onreadystatechange?=?updatePage;
          ????
          //發送請求
          ????xmlHttp.send(null);
          ???}
          ???
          else
          ???{
          ????document.getElementById(
          "flag").innerHTML?=?"XMLHTTP對象創建失敗";
          ???}
          ??}
          ??
          catch?(e)
          ??{
          ???document.getElementById(
          "flag").innerHTML?=?"查詢錯誤:"?+?e;
          ??}
          ?}
          ?
          ?
          //回調處理函數
          ?function?updatePage()
          ?{
          ??
          try?{
          ???
          if?(xmlHttp.readyState?==?1)
          ???{
          ????document.getElementById(
          "flag").innerHTML?=?"正在加載連接對象";
          ???}

          ???
          if?(xmlHttp.readyState?==?2)
          ???{
          ????document.getElementById(
          "flag").innerHTML?=?"連接對象加載完畢。";
          ???}

          ???
          if?(xmlHttp.readyState?==?3)
          ???{
          ????document.getElementById(
          "flag").innerHTML?=?"數據獲取中";
          ???}

          ???
          if?(xmlHttp.readyState?==?4)
          ???{
          ????
          var?response?=?xmlHttp.responseText;
          ????document.getElementById(
          "out").innerHTML?=?response;
          ????document.getElementById(
          "outgroup").style.display?=?"";
          ???}
          ??}
          ??
          catch?(e)
          ??{
          ??????document.getElementById(
          "flag").innerHTML?=?"回調處理錯誤:"?+?e;
          ??}
          ?}

          ?
          //創建日期選擇下拉框
          ?function?CreateDateSelect()
          ?{

          ??
          var?html?=?[];
          ?????????
          ??
          for(var?iYear=2005;?iYear<=2006;?iYear?++)
          ??{
          ???
          for(?var?iMonth=1;?iMonth<=12;?iMonth?++?)
          ???{
          ????
          for(?var?iDay=1;?iDay<=31;?iDay?++?)
          ????{?
          ????html[html.length]?
          =?"<option?value=\""??+?iYear?+?"\-"?+?iMonth?+?"\-"?+?iDay?+?"\">"?+?iYear?+?""?+?iMonth?+?""?+?iDay?+?""?+?"</option>";
          ????}
          ???}
          ??}
          ??????
          ??document.getElementById(
          "dateSele").innerHTML?=?"<select?name=\"dateSele\"?id=\"dateSele\"?onchange=\"callServer(this);\">"?+?html.join("")?+?"</select>";
          ?}?
          ?
          </script>


          posted @ 2008-01-09 09:46 G_G 閱讀(1160) | 評論 (0)編輯 收藏

               摘要: 嘗試著繼承關系和xdoclet使用后,對數據庫面向對象的使用更近一步。這次例子從開始到結束,都沒有接觸面向結構的數據庫設計;并完全在代碼中以面向對象的形式來設計的。hbn 的繼承映射關系有這幾種;繼承關系類共同使用一個表; 每個子類一個表(mapping全); 每個具體內一個表(mapping只有父類)。先說說3把,感覺這點最好用-》》繼承關系描述:? Animals父類 -- Bird ...  閱讀全文

          posted @ 2007-12-26 11:41 G_G 閱讀(1110) | 評論 (0)編輯 收藏

          圣誕將至,許下了一個愿望,希望程序員都是幸福的,快樂的,沒有煩惱,沒有委屈,愛自己,幸福
          (關鍵的是寫出來的代碼全都是綠的!)


          posted @ 2007-12-24 18:23 G_G 閱讀(1194) | 評論 (8)編輯 收藏

          學習xdoclet 發現是很有用的。易于規范,使用方便;
          參考: http://blog.easyjf.com/html/blog/20061127/3290288676803397.htm
          官方完整API: Template Language (*.xdt)

          因為參考中:是還是比較復雜的例(數本人愚鈍^_^)特留一文:
          1>ant編輯文件
          <?xml?version="1.0"?encoding="UTF-8"?>
          <project?name="xdocletExample"?default="doall"?basedir=".">
          ????
          <property?name="basedir"?location="E:\ue_test\xdoclet"?/>
          ????
          <property?name="xdoclet.lib.dir"?location="D:\hbn\hibernate-3.2\xdoclet-1.2.3\lib"?/>

          ????
          <property?name="gen.src.dir"?location="${basedir}/target"?/>
          ????
          <property?name="src.dir"?location="${basedir}/src"?/>
          ????
          <property?name="template.dir"?location="${basedir}/template"?/>
          ????
          <property?name="customtag.dir"?location="${basedir}/bin"?/>

          ????
          <path?id="xdoclet.lib.path">
          ???????
          <fileset?dir="${xdoclet.lib.dir}"?includes="*.jar"?/>
          ????
          </path>

          ????
          <taskdef?name="xdoclet"?classname="xdoclet.DocletTask"?classpathref="xdoclet.lib.path"?/>???

          ????
          <target?name="init"?/>

          ????
          <target?name="daogener"?depends="init">
          ???????
          <xdoclet?destdir="${gen.src.dir}">
          ???????????
          <fileset?dir="${src.dir}"?includes="${cjava.file}"?/>
          ???????????
          <template?templateFile="${xdt.file}"?acceptInterfaces="false"?acceptAbstractClasses="false"?destinationfile="{0}DAO.java"?/>
          ???????
          </xdoclet>
          ????
          </target>

          ????
          <target?name="doall"?depends="daogener,daoimplgener"?/>

          </project>

          在運行上面文件時候動態輸入參數
          ?1.依照的 .java 文件( cjava.file );
          ?2.依照的 .xdt.file 文件( xdt.file );

          比如DOS中輸入:
          E:\ue_test\xdoclet>ant daogener
          -Dxdt.file=template\daointerface.xdt
          -Dcjava.file=test\TestXDoclet.java

          2.參考的java文件(簡單過頭了 呵呵)
          package?test;
          ??
          /**
          ??*?@hasRef
          ??
          */
          public?class?TestXDoclet{
          ????
          /**
          ?????*?@ref.model?name="sytp"
          ?????
          */
          ????
          private?PubSystype?sytp;

          ????
          private String gg;
          }

          3.xdt 模板
          ? 標簽解釋:
          ? <XDtClass:ifHasClassTag?tagName="hasRef">判斷 java文件中有 @hasRef
          ?
          <XDtField:forAllFields>? 1> 循環查找
          ?
          ? 2>判斷有@ref.model?name=。。
          ? <XDtField:ifHasFieldTag?tagName="ref.model"?paramName="name">
          ?
          ? 3>取值
          ??
          <XDtField:fieldTagValue?tagName="ref.model"?paramName="name"?/> ?

          package?com.hycs.bs.client.itf;

          import?java.util.List;

          //這是?packageName.className?這和好理解
          import?
          <XDtPackage:packageName?/>.<XDtClass:className?/>;

          public?interface?
          <XDtClass:className?/>DAO?{

          ????//添加
          ????boolean?add(
          <XDtClass:className?/>?instance);
          ????
          ????//邏輯添加
          ????
          <XDtClass:ifHasClassTag?tagName="hasRef">
          ????????boolean?add(
          <XDtClass:className?/>?instance,
          ????????????????
          <XDtField:forAllFields>
          ????????????????????
          <XDtField:ifHasFieldTag?tagName="ref.model"?paramName="name">?
          ????????????????????????String?
          <XDtField:fieldTagValue?tagName="ref.model"?paramName="name"?/>
          ????????????????????
          </XDtField:ifHasFieldTag>
          ????????????????
          </XDtField:forAllFields>);??
          ????
          </XDtClass:ifHasClassTag>

          ????//更新
          ????boolean?update(
          <XDtClass:className?/>?instance);


          ????//得到一個對象
          ????
          <XDtClass:className?/>?get(String?pkid);
          }

          運行DOS->
          E:\ue_test\xdoclet>ant daogener
          -Dxdt.file=template\daointerface.xdt
          -Dcjava.file=test\TestXDoclet.java

          得到的代碼:
          package?com.hycs.bs.client.itf;

          import?java.util.List;

          //這是?packageName.className?這和好理解
          import?test.TestXDoclet;

          public?interface?TestXDocletDAO?{

          ????
          //添加
          ????boolean?add(TestXDoclet?instance);
          ????
          //邏輯添加
          ????????boolean?add(TestXDoclet?instance,String?sytp);?
          ????
          //更新
          ????boolean?update(TestXDoclet?instance);

          ????
          //得到一個對象
          ????TestXDoclet?get(String?pkid);
          }






          posted @ 2007-12-24 17:54 G_G 閱讀(1490) | 評論 (0)編輯 收藏

          為了了解hbm的rmic真正的威力還有為了更近一步了解;在此特使用文本和dos命令完成這次學習。
          在此讀者最好先做好不使用 IDE 的準備(^_^!? 文本編輯,dos編輯和運行)
          閱讀需要:
          ?java,javac,rmiregistry,rmic,ant 等命令有所涉及(只是簡單使用,不會也別怕!)

          可行性使用說明:
          ? 持久層程序員成功開啟rmiregistry服務,在局域網內其他使用數據的隊友就只要加載
          hbmBean 的映射jar和 dao接口jar后 就可以取得數據。根本感覺不到hbn使用。
          優點:
          1.其他隊員編譯classpath中不需要hbm的任何東西,跟關注自己東西。
          2.強制接口規范。
          3.正交編程。
          4.DAO測試性能方便。
          5.這還是 EJB 原理,轉換容易。

          缺點:
          1.rmic 突破放火墻能力有限,可以換成EJB
          2.大型項目注冊服務器,配置繁瑣,可以使用EJB3.0
          ?


          使用:
          1.jdk1.5
          2.jar使用(為了用hbm)?????
          ? ? jta.jar;
          ??? asm.jar;
          ? ? commons-collections-2.1.1.jar;
          ? ? commons-logging-1.0.4.jar;
          ? ? hibernate3.jar;
          ??? dom4j-1.6.1.jar;
          ??? cglib-2.1.3.jar;
          ? ? antlr-2.7.5H3.jar
          ??? MYSQL.jar
          3.ant1.7(使用hbm生成 mapping;config...)
          4.Middlegen-Hibernate-r5 同上
          5.使用文件路徑
          ? E:\rmi_test->
          ???? +-src
          ???? --hibernate3.xml
          ???? --hibernate3_ant.properties

          開始:
          ?1>使用ant 對 hbm? 配置映射參考 :ant 項目實際 并使用 hibernate3.xml
          ??? dos 輸入 -> ant -f hibernate3.xml ddl2hbm (使用了Middlegen-Hibernate-r5)
          ???????????? -> ant -f hibernate3.xml create_config (hibernate.cfg.xml建立)
          ??? 在 hibernate.cfg.xml中添加-> <mapping resource="hibernate\Liu.hbm.xml" />
          ??? dos 輸入 -> ant -f hibernate3.xml hbm2java
          ?
          變成+-src
          ?????? |-hibernate
          ????????? |-Liu.hbm.xml
          ????????? |-Liu.java
          ?????? |-hbmConfig
          ????????? |-hibernate.cfg.xml
          ?2>手動建hbmHibernateSessionFactory在hbmConfig文件中(為了簡單copy->myeclipes生成的)
          package???hbmConfig;?
          import?org.hibernate.HibernateException;
          import?org.hibernate.Session;
          import?org.hibernate.cfg.Configuration;
          /**
          ?*?Configures?and?provides?access?to?Hibernate?sessions,?tied?to?the
          ?*?current?thread?of?execution.??Follows?the?Thread?Local?Session
          ?*?pattern,?see?{
          @link?http://hibernate.org/42.html}.
          ?
          */
          public?class?HibernateSessionFactory?{

          ????
          /**?
          ?????*?Location?of?hibernate.cfg.xml?file.
          ?????*?NOTICE:?Location?should?be?on?the?classpath?as?Hibernate?uses
          ?????*?#resourceAsStream?style?lookup?for?its?configuration?file.?That
          ?????*?is?place?the?config?file?in?a?Java?package?-?the?default?location
          ?????*?is?the?default?Java?package.<br><br>
          ?????*?Examples:?<br>
          ?????*?<code>CONFIG_FILE_LOCATION?=?"/hibernate.conf.xml".?
          ?????*?CONFIG_FILE_LOCATION?=?"/com/foo/bar/myhiberstuff.conf.xml".</code>?
          ?????
          */
          ????
          private?static?String?CONFIG_FILE_LOCATION?=?"/hbmConfig/hibernate.cfg.xml";

          ????
          /**?Holds?a?single?instance?of?Session?*/
          ????
          private?static?final?ThreadLocal<Session>?threadLocal?=?new?ThreadLocal<Session>();

          ????
          /**?The?single?instance?of?hibernate?configuration?*/
          ????
          private?static?final?Configuration?cfg?=?new?Configuration();

          ????
          /**?The?single?instance?of?hibernate?SessionFactory?*/
          ????
          private?static?org.hibernate.SessionFactory?sessionFactory;

          ????
          /**
          ?????*?Returns?the?ThreadLocal?Session?instance.??Lazy?initialize
          ?????*?the?<code>SessionFactory</code>?if?needed.
          ?????*
          ?????*??
          @return?Session
          ?????*??
          @throws?HibernateException
          ?????
          */
          ????
          public?static?Session?currentSession()?throws?HibernateException?{
          ????????Session?session?
          =?(Session)?threadLocal.get();

          ????????
          if?(session?==?null)?{
          ????????????
          if?(sessionFactory?==?null)?{
          ????????????????
          try?{
          ????????????????????cfg.configure(CONFIG_FILE_LOCATION);
          ????????????????????sessionFactory?
          =?cfg.buildSessionFactory();
          ????????????????}
          ????????????????
          catch?(Exception?e)?{
          ????????????????????System.err.println(
          "%%%%?Error?Creating?SessionFactory?%%%%");
          ????????????????????e.printStackTrace();
          ????????????????}
          ????????????}
          ????????????session?
          =?sessionFactory.openSession();
          ????????????threadLocal.set(session);
          ????????}

          ????????
          return?session;
          ????}

          ????
          /**
          ?????*??Close?the?single?hibernate?session?instance.
          ?????*
          ?????*??
          @throws?HibernateException
          ?????
          */
          ????
          public?static?void?closeSession()?throws?HibernateException?{
          ????????Session?session?
          =?(Session)?threadLocal.get();
          ????????threadLocal.set(
          null);

          ????????
          if?(session?!=?null)?{
          ????????????session.close();
          ????????}
          ????}

          ????
          /**
          ?????*?Default?constructor.
          ?????
          */
          ????
          private?HibernateSessionFactory()?{
          ????}

          }

          dos中編譯->
          E:\rmi_test\src>javac -cp?? .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\hibernate3.jar???
          hbmConfig/*.java


          3>DAO實現
          接口->
          package?rmic;

          import?java.rmi.Remote;
          import?java.rmi.RemoteException;

          public?interface?IHello?extends?Remote?{
          ????
          public?String?sayHello(String?id)?throws?RemoteException;
          }

          實現類->
          package?rmic;

          import?java.rmi.Naming;
          import?java.rmi.RemoteException;
          import?java.rmi.server.UnicastRemoteObject;
          //取消顯示指定的編譯器警告!
          //參考?:?http://gceclub.sun.com.cn/Java_Docs/html/zh_CN/api/java/lang/SuppressWarnings.html
          @SuppressWarnings("serial")
          public?class?Hello?extends?UnicastRemoteObject?implements?IHello?{
          ????
          public?Hello()?throws?RemoteException?{
          ????????
          super();
          ????}
          ????
          ????
          public?void?rebind(String?name)?{?
          ????????
          try?{
          ????????????Naming.rebind(name,
          this);
          ????????????System.out.println(
          "Server?is?running");
          ????????}?
          catch(Exception?e)?{
          ????????????e.printStackTrace();
          ????????}
          ????}
          ????
          public?String?sayHello(String?id)?throws?RemoteException?{
          ????????System.out.println(
          "run?Server.");
          ????????
          ????org.hibernate.Session?session?
          =?hbmConfig.HibernateSessionFactory.currentSession();
          ????org.hibernate.Query?qu?
          =?session.createQuery("from?Liu?lt?where?lt.id=:id");
          ????hibernate.Liu?ll?
          =?(hibernate.Liu)qu.setString("id"
          ,id).uniqueResult();
          ????hbmConfig.HibernateSessionFactory.closeSession();


          ????????
          return?"Hello?"+ll.getName()+"?This?is?processed?by?RMI";
          ????}

          }

          dos編譯->
          E:\rmi_test\src>javac -cp .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.
          2\hibernate3.jar? rmic/*.java

          4>java注冊機開啟
          E:\rmi_test\src>rmiregistry 1099

          5> 本例簡單服務器開啟
          package?start;

          import?java.rmi.RMISecurityManager;
          import?rmic.Hello?;

          public?class?Start?{

          ????
          public?static?void?main(String[]?args)?{
          ????????
          try?{
          ????????????
          //System.setSecurityManager(new?RMISecurityManager());
          ????????????new?Hello().rebind("RMI/Mclaren");
          ????????}?
          catch(Exception?e)?{
          ????????????e.printStackTrace();
          ????????}
          ????}
          }

          dos編譯->E:\rmi_test\src>javac? start/*.java
          運行->
          java -classpath .;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\jta.jar;
          D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\asm.jar;
          D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\commons-collections-2.1.1.jar;
          D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\commons-logging-1.0.4.jar;
          D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\hibernate3.jar;
          D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\dom4j-1.6.1.jar;
          E:\lib\MYSQL.JAR;D:\hbn\hibernate-3.2\hibernate-3.2.5.ga\hibernate-3.2\lib\cglib-2.1.3.jar;
          E:\and\ant\bin\antlr-2.7.5H3.jar
          ? start.Start


          6>客戶端
          ?得到存根Hello_Stub.class-> E:\rmi_test\src>rmic rmic.Hello
          ?換個地方:c:\\TT 并copy rmic中的IHello.class和Hello_Stub.class連同目錄rmic一同copy
          package?client;

          import?java.rmi.Naming;
          import?rmic.IHello;

          public?final?class?Client?{
          ????
          public?static?void?main(String[]?args)?{
          ????????System.out.println(
          "client.");
          ????????
          try?{
          ????????????IHello?hello?
          =?(IHello)Naming.lookup("rmi://localhost:1099/RMI/Mclaren");
          ????????????System.out.println(hello.sayHello(
          "1"));
          ????????}?
          catch(Exception?e)?{
          ????????????e.printStackTrace();
          ????????}
          ????}

          }

          ?dos編譯-> C:\TT>javac -d . Client.java
          ?C:\TT>java client.Client
          ?client....
          ?Hello gg This is processed by RMI (gg就是數據 成功! )

          mysql> select * from liu;
          +----+------+-----+
          | id | name | avg |
          +----+------+-----+
          |? 1 | gg?? |? 24 |
          +----+------+-----+








          posted @ 2007-12-24 13:36 G_G 閱讀(1102) | 評論 (4)編輯 收藏

          我 的 春天spring 正式開始 !^_^
          spring項目基本需要jar->commons-logging.jar;log4j-1.2.9.jar;spring.jar
          參考:http://www.redsaga.com/spring_ref/2.0/html/beans.html

          本文主要內容:
          1.單多配置文件的使用
          2.動態替換類方法(cglib)
          3.
          自定義作用域bean
          4.定制bean特性


          1).單多配置文件的使用
          1.1)配置文件:beans.xml格式(基本配置)
          <?xml?version="1.0"?encoding="UTF-8"?>
          <!DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN//EN"?
          ????"http://www.springframework.org/dtd/spring-beans.dtd"
          >
          <beans>
          ????
          <bean?id="userBean"?name="userBean"?
          ??????????class
          ="springtest.UserBean"?
          ??????????abstract
          ="false"?
          ??????????singleton
          ="true"?
          ??????????lazy-init
          ="default"
          ??????????autowire
          ="default"?
          ??????????dependency-check
          ="default"?>
          ????????????
          <property?name="name">
          ????????????????
          <value>bea</value>
          ????????????
          </property>
          ????
          </bean>
          ????
          </beans>

          spring 工廠建立單配置和多配置文件
          ??? //單配置文件加載
          ??? public
          ?void?testSp()throws?Exception{
          ????????Resource?res?
          =?new?FileSystemResource(
          ????????????
          this.getClass().getClassLoader().getResource("config/beans.xml").getPath()
          ????????????????);
          ????????BeanFactory?fac?
          =?new?XmlBeanFactory(res);
          ????????UserBean?uu?
          =?(UserBean)?fac.getBean("userBean");
          ????????System.out.println(uu.getName());
          ????????System.out.println(uu.getAge());
          ????}
          ??? //多配置文件加載
          ????public?void?testSps()?throws?Exception?{
          ????????ApplicationContext?act
          =new?ClassPathXmlApplicationContext(
          ??? ??? ???
          new?String[]?{"config/beans.xml",.....}
          ??? ??? );
          ????????UserBean?uu?
          =?(UserBean)act.getBean("userBean");
          ????????System.out.println(?uu.getName());
          ????}
          1.2) 還用一種是單配置多<import resource="。.xml"/>達到多配置
          <?xml?version="1.0"?encoding="UTF-8"?>
          <!DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN//EN"?
          ????"http://www.springframework.org/dtd/spring-beans.dtd"
          >
          <beans>
          ????
          <import?resource="beans_2.xml"/>
          ????
          <bean?id="userBean"?name="userBean"?
          ??????????class
          ="springtest.UserBean"?
          ??????????abstract
          ="false"?
          ??????????singleton
          ="true"?
          ??????????lazy-init
          ="default"
          ??????????autowire
          ="default"?
          ??????????dependency-check
          ="default"?>
          ????????????
          <property?name="name">
          ????????????????
          <ref??bean="str1"/>
          ????????????
          </property>
          ????
          </bean>
          </beans>

          加載就用上的 -》
          單配置文件加載

          2).動態替換類方法(cglib)
          配置文件中 替換方法(替換方法 getName ) lib中加入 cglib.jar
          <?xml?version="1.0"?encoding="UTF-8"?>
          <!DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN//EN"?
          ????"http://www.springframework.org/dtd/spring-beans.dtd"
          >
          <beans>
          ????
          <import?resource="beans_2.xml"/>
          ????
          <bean?id="userBean"?name="userBean"?
          ??????????class
          ="springtest.UserBean"?
          ??????????abstract
          ="false"?
          ??????????singleton
          ="true"?
          ??????????lazy-init
          ="default"
          ??????????autowire
          ="default"?
          ??????????dependency-check
          ="default"?>
          ??????????????
          <replaced-method?name="getName"?replacer="rm">
          ??????????????????
          <arg-type>String</arg-type>
          ??????????????
          </replaced-method>

          ????????????
          <property?name="name">
          ????????????????
          <ref??bean="str1"/>
          ????????????
          </property>
          ????
          </bean>
          ????
          ????
          <bean?id="rm"?class="springtest.ReplacedMethod"/>
          </beans>

          springtest.ReplacedMethod類
          package?springtest;

          import?java.lang.reflect.Method;

          import?org.springframework.beans.factory.support.MethodReplacer;

          public?class?ReplacedMethod?implements?MethodReplacer?{
          ????
          ????
          public?Object?reimplement(Object?arg0,?Method?arg1,?Object[]?arg2)?throws?Throwable?{
          ????????
          return?"劉凱毅";
          ????}
          }

          結果: 不管你怎么setName getName出來的都是-》 “劉凱毅”

          3.自定義作用域bean 需要jdk1.5


          4.定制bean特性
          1)初始化回調 <bean id=".." class=".." init-method="init"/> 方法init()
          ? 和 繼承org.springframework.beans.factory.InitializingBean 實現接口方法
          ??? void afterPropertiesSet() throws Exception; 一樣
          2)

          posted @ 2007-12-21 16:33 G_G 閱讀(462) | 評論 (0)編輯 收藏

          學習了Rmic后 ,聯系自己hbm的一些想法。并在實際開發中做到分離持久層.
          在次,特留記錄。使用不當望大家踴躍拍磚!EJB原理學習_RMIC

          效果先上 (你的組員,不需要數據庫,不需要hbm,不需要配置文件)
          客戶端:在服務器開啟,并client端內classpath 包含有 *_Stub.class 和 hbmBean等類(底下有ant簡化部署) 在內網中隨便那臺電腦都可以中運行,那臺開發電腦可以沒有hbm,可以沒有數據庫
          package?Client;

          import?java.rmi.Naming;

          import?dao.ILiuDao;
          import?dao.LiuDaoRemote;
          import?dao.imp.DaoFactory;

          public?class?Client?{
          ????
          public?static?void?main(String[]?args)?{
          ????????
          try?{
          ????????????ILiuDao?hello?
          =?(ILiuDao)Naming.lookup("rmi://192.168.1.109:1099/RMI/LiuDaoRemote");
          ????????????System.out.println(hello.getLiu(
          "1").getName());
          ??????}?
          catch(Exception?e)?{
          ????????????e.printStackTrace();
          ????????}
          ????}
          }

          服務器端:
          dao需求接口? 其他隊員提供給管理持久層的隊員
          package?dao;

          import?java.rmi.Remote;
          import?java.rmi.RemoteException;

          import?hibernate.Customer;
          import?hibernate.Liu;

          public?interface?ILiuDao?extends?Remote{
          ????
          public?abstract?Liu?getLiu(String?id)?throws?RemoteException;
          }

          dao實現
          package?dao;

          import?java.rmi.Naming;
          import?java.rmi.RemoteException;
          import?java.rmi.server.UnicastRemoteObject;

          import?org.hibernate.Query;
          import?org.hibernate.Session;

          import?hbmConfig.HibernateSessionFactory;
          import?hibernate.Customer;
          import?hibernate.Liu;

          public?class?LiuDaoRemote?extends?UnicastRemoteObject?implements?ILiuDao?{
          ????
          public?LiuDaoRemote()?throws?RemoteException?{
          ????????
          super();
          ????}

          ????
          public?Liu?getLiu(String?id)throws?RemoteException{
          ????????Liu?ll?
          =??null?;
          ????????Session?session?
          =?HibernateSessionFactory.currentSession();
          ????????Query?qu?
          =?session.createQuery("from?Liu?lt?where?lt.id=:id");
          ????????ll?
          =?(Liu)qu.setString("id",id).uniqueResult();
          ????????HibernateSessionFactory.closeSession();
          ????????
          return?ll?;
          ????}
          }

          使用ant給客戶端提供 jar

          ????<target?name?=?"rmic">
          ????????
          <rmic?base="${class}"?includes="${rmic.package}/**/*Remote.class"/>
          ??? ??? <!-- 兩個jar 包 ,給客戶端提供的
          ???? ??? ??? 1. rmic帶有約定的 到入 *_Stub.class并除dao實現類(*Remote.class
          )打包
          ??? ?? ?? ?? 2. hbmBean 道入 hbmjava
          ? ? ? ?? -->
          ????????
          <jar?destfile="${rh.dir}/rmic.jar">
          ????????????
          <fileset?dir="${class}">
          ??????????????
          <include?name="${rmic.package}/**/*.class"?/>
          ??????????????
          <exclude?name="${rmic.package}/**/*Remote.class"/>
          ????????????
          </fileset>
          ????????
          </jar>
          ????????
          <jar?destfile="${rh.dir}/hbmBean.jar"?>
          ????????????
          <fileset?dir="${class}">
          ??????????????
          <include?name="${hbm.bean.package}/**/*.class"?/>
          ????????????
          </fileset>
          ????????
          </jar>????
          ????
          </target>


          開啟服務器:
          package?test;

          import?java.rmi.Naming;
          import?java.rmi.RMISecurityManager;
          import?java.rmi.RemoteException;
          import?java.rmi.registry.LocateRegistry;

          import?sun.awt.AppContext;

          import?dao.DaoFactoryRemote;
          import?dao.ILiuDao;
          import?dao.LiuDaoRemote;

          import?hibernate.Liu;

          public?class?StartMain?{
          ????
          ????
          public?static?void?main(String[]?args)?throws?Exception?{
          ???????????
          try?{?
          ????????????????System.setProperty(
          "java.security.policy",?"rmi.policy");??
          ????????????????LocateRegistry.createRegistry(
          1099);??
          ????????????????Naming.rebind(
          "RMI/LiuDaoRemote",?new?LiuDaoRemote());?
          ????????????}?
          catch(Exception?e)?{
          ????????????????e.printStackTrace();
          ????????????}
          ????}

          }




          posted @ 2007-12-18 17:47 G_G 閱讀(1101) | 評論 (0)編輯 收藏

          僅列出標題
          共16頁: First 上一頁 4 5 6 7 8 9 10 11 12 下一頁 Last 
          主站蜘蛛池模板: 武城县| 宜州市| 页游| 奇台县| 云和县| 丰顺县| 汉沽区| 牟定县| 那曲县| 措美县| 苍梧县| 富阳市| 绍兴县| 宁远县| 博白县| 鄂托克旗| 新竹市| 湘潭市| 翁牛特旗| 万荣县| 雅江县| 大城县| 靖安县| 龙井市| 汉寿县| 东城区| 塔河县| 吴旗县| 河间市| 肥东县| 信阳市| 万山特区| 加查县| 尼木县| 龙州县| 绵竹市| 湟中县| 揭东县| 孝感市| 海兴县| 温宿县|