<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    心的方向

    新的征途......
    posts - 75,comments - 19,trackbacks - 0

    今天要實現一個在頁面中動態添加以及刪除一行列表的功能,查找了幾種方法,在此備份,以便日后使用:

    ========================此方法比較簡潔,而且可以解決問題========================
    function deleteCurrentRow()//刪除當前行
    {
      var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;
      document.all.table10.deleteRow(currRowIndex);//table10--表格id
    }


    function insertRow()
    {
      var nRow=document.all.table10.rows.length; //表格的總行數
      var objTheRow=document.all.table10.insertRow(nRow);//在最下邊新增一行
      objTheRow.insertCell(0);//新增一個單元格
      objTheRow.insertCell(1);
      objTheRow.insertCell(2);
      objTheRow.cells(0).innerHTML=nRow;//對新增的單元格?容
      objTheRow.cells(1).innerHTML="&nbsp;";
      objTheRow.cells(2).innerHTML="<input type='button' value='del this row' onClick='deleteCurrentRow()'>";
    }

    ====================我的程序代碼======================
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <META http-equiv="Content-Type" content="text/html; charset=GB18030">
    <META name="GENERATOR" content="IBM WebSphere Studio">
    <TITLE>cfbcard.html</TITLE>
    </HEAD>

    <SCRIPT language="JavaScript">
    var j_1 = 1;
    function add_row_family(){
     newRow=document.all.family.insertRow(-1) 
     
     newcell=newRow.insertCell() 
     newRow.bgColor='#FFFFFF';
     newcell.className='STYLE3';
     newcell.align='center';
     //newcell.innerHTML="<input type='text' name='familyname"+j_1+"' style='WIDTH: 60px; font-size:9pt; color:#000000' />";
     newcell.innerHTML="<SELECT name='thesistogether"+j_1+"'>"+
                            " <option value='請選擇'>"+
          "   請選擇"+
          "  </option>"+
          "  <option value='1'>"+
          "   111"+
          "  </option>"+
          "  <option value='2'>"+
          "   222"+
          "  </option>"+
          "  <option value='3'>"+
          "   333"+
          "  </option>"+
          "  <option value='4'>"+
          "   444"+
          "  </option>"+
          "  <option value='5'>"+
          "   555"+
          "  </option>"+
          
                           "</SELECT>";
     for(var i = 0;i<12;i++){
     newcell=newRow.insertCell() ;
     newRow.bgColor='#FFFFFF';
     newcell.className='STYLE3';
     newcell.align='center';
     newcell.innerHTML="<input type='text' name='familyrelation"+j_1+"' style='WIDTH: 60px; font-size:9pt; color:#000000' />";
    }
     
     newcell=newRow.insertCell() ;
     newRow.bgColor='#FFFFFF';
     newcell.className='STYLE3';
     newcell.align='center';
     //newcell.innerHTML="<a href='javascript:delTableRow(\""+1+"\")'>刪除</a>";
      newcell.innerHTML="<input type='button' value='刪除' onClick='deleteCurrentRow()'>";

     j_1++;
     document.all.j_1.value=j_1;
     document.all.family.focus();
    }


     
     
     function deleteCurrentRow()//刪除當前行
    {
      var currRowIndex=event.srcElement.parentNode.parentNode.rowIndex;
      document.all.family.deleteRow(currRowIndex);//table10--表格id
    }


    </script>

    <body bgcolor="#F5F1F5"  >

    <form name="form1" method="post" action="" onsubmit="">
    <table>
    <tr>
          <td align="right"><INPUT type="button" name="add" onclick="add_row_family();" value="添加"></td>
    </tr>
    <tr>
         <td>
     <table id="family" style="width:100%" border="1" cellspacing="1" cellpadding="2" class="tbMain">
            <tr>
       <td class="td_name">111</td>
       <td class="td_name">222</td>
       <td class="td_name">333</td>
       <td class="td_name">444</td>
       <td class="td_name">555</td>
       <td class="td_name">666</td>
       <td class="td_name">777</td>
       <td class="td_name">888</td>
       <td class="td_name">999</td>
       <td class="td_name">000</td>
       <td class="td_name">123</td>
       <td class="td_name">456</td>
       <td class="td_name">789</td>
          <td class="td_name">刪除</td>
         </tr>
           
        </table>
        </td>
     </tr>
    </table>
    </form>
    </body>
    </html>

    =================================另外一種方法==============
    如何刪除表格的行上次講到了如何動態給表格增加行,那么這次就講講如何刪除表格的行了。首先建立一個表格,
    <table border="1">
     <tr>
      <td>姓名</td>
      <td>地址</td>
     </tr>
     <tbody id="mainbody">
     <tr id="delCell">
      <td>name</td>
      <td>address</td>
     </tr>
     </tbody>
    </table>
    取得tbody的元素var mailbody = document.getElementById("mainbody");,
    接著取得要刪除行的元素var cell = document.getElementById("delCell");
    最后就是從tbody中移去要刪除的行就可以了mainbody.removeChild(cell);
    完整的代碼如下:
    <html>
    <head>
     <title>動態刪除表格的行</title>
     <script type="text/javascript">
     function deleteCell(){
      var mailbody = document.getElementById("mainbody");
      var cell = document.getElementById("delCell");
      if(cell!=undefined){
         mainbody.removeChild(cell);
      }
     }
    </script>
    </head>
    <body>
    <table border="1">
     <tr>
      <td>姓名</td>
      <td>地址</td>
     </tr>
     <tbody id="mainbody">
     <tr id="delCell">
      <td>name</td>
      <td>address</td>
     </tr>
     </tbody>
    </table>

    <input type="button" value="刪除" onclick="deleteCell()"/>
    </body>
    <html>

    posted @ 2007-04-18 23:49 阿偉 閱讀(2937) | 評論 (2)編輯 收藏

    在jsp中使用smartupload組件上傳文件[轉]

    jsp對上傳文件的支持不象php中支持的那么好,直接做成了函數,也不象asp中要通過組件才能實現。jsp中可以通過javabean來實現。但是我們沒有必要自己去寫一個上載的bean,在網上已經有了很多成型的技術,smartupload就是其中的一個。但是smartupload是將文件先讀到服務器的內存中,所以上傳太大的文件(超過100兆)有可能會出問題,也算是一個美中不足吧:)

       先說一下提交的頁面,smartupload組件要求用字節流的方式來提交<FORM action="upload.jsp"  encType=multipart/form-data method=post>。下面就是個例子upload.htm:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!-- saved from url=(0057)
    http://localhost:8080/jspsmartfile/jsp/uploadTemplate.jsp -->
    <HTML><HEAD>
    <META content="text/html; charset=gb2312" http-equiv=Content-Type>
    <META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
    <BODY bgColor=#e6e6e6><BR>
    <FORM action="upload.jsp"  encType=multipart/form-data method=post>
    <TABLE>
      <TBODY>
      <TR>
        <TD><FONT color=#000000 face=helv,helvetica size=1>&nbsp;&nbsp;File 
          :&nbsp;</FONT>&nbsp;&nbsp;<INPUT  size=60 type=file  name="file"></TD></TR>
            <TR>
        <TR>
        <TD><FONT color=#000000 face=helv,helvetica size=1>&nbsp;&nbsp;File 
          :&nbsp;</FONT>&nbsp;&nbsp;<INPUT  size=60 type=file  name="file1"></TD></TR>
            <TR>  
        <TD><FONT color=#000000 face=helv,helvetica size=1>&nbsp;&nbsp;File 
          :&nbsp;</FONT>&nbsp;&nbsp;<INPUT  size=60 type=text  name="text"></TD></TR>
      <TR>
        <TD
    align=right><INPUT type=submit value=Send name="send"></TD></TR></TBODY></TABLE></FORM></BODY></HTML>

      再來看一下接收的頁面 ,我們把文件上傳到服務器以后就直接把它再存入數據庫中:upload.jsp

    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="com.jspsmart.upload.*" %>
    <%@ page import="DBstep.iDBManager2000.*"%>
    <%
       
    //實例化上載bean
        com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
       
    //初始化
        mySmartUpload.initialize(pageContext); 
       
    //設置上載的最大值
        mySmartUpload.setMaxFileSize(500 * 1024*1024);
       
    //上載文件
        mySmartUpload.upload();
      
    //循環取得所有上載的文件
       for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
      
    //取得上載的文件
       com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
       if (!myFile.isMissing())
        {
      
    //取得上載的文件的文件名
        String myFileName=myFile.getFileName();
       
    //取得不帶后綴的文件名
        String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
       
    //取得后綴名
        String  ext= mySmartUpload.getFiles().getFile(0).getFileExt();  
       
    //取得文件的大小 
        int fileSize=myFile.getSize();
       
    //保存路徑
        String aa=getServletContext().getRealPath("/")+"jsp\\";
        String trace=aa+myFileName;
       
    //取得別的參數
        String explain=(String)mySmartUpload.getRequest().getParameter("text");
        String send=(String)mySmartUpload.getRequest().getParameter("send");
       
    //將文件保存在服務器端
        myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
       
    //下面的是將上載的文件保存到數據庫中
       
    //將文件讀到流中
        java.io.File file = new java.io.File(trace);
        java.io.FileInputStream fis = new java.io.FileInputStream(file);
      out.println(file.length());
      
    //打開數據庫
       ResultSet result=null;
       String mSql=null;
       PreparedStatement prestmt=null;
       DBstep.iDBManager2000 DbaObj=new DBstep.iDBManager2000();
       DbaObj.OpenConnection();
      
    //將文件寫到數據庫中
       mSql="insert into marklist (markname,password,marksize,markdate,MarkBody) values (?,?,?,?,?)";
       prestmt =DbaObj.Conn.prepareStatement(mSql);
       prestmt.setString(1, "aaa1");
       prestmt.setString(2, "0000");
       prestmt.setInt(3, fileSize);
       prestmt.setString(4, DbaObj.GetDateTime());
       prestmt.setBinaryStream(5,fis,(int)file.length());
       DbaObj.Conn.setAutoCommit(true) ;
       prestmt.executeUpdate();
       DbaObj.Conn.commit();
       out.println(("上載成功!!!").toString());
       }
       else
       { out.println(("上載失敗!!!").toString()); }
       }//與前面的if對應
    %>

       再說一下下載,下載分兩種情況1。從數據庫直接下載2。從服務器上下載

      先說從數據庫直接下載的情形:就是把輸入流從數據庫里讀出來,然后轉存為文件

    <%@ page contentType="text/html; charset=gb2312" %>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.io.*" %>
    <%@ page import="DBstep.iDBManager2000.*"%>
    <%
        int bytesum=0;
        int byteread=0;
     
    //打開數據庫
      ResultSet result=null;
      String Sql=null;
      PreparedStatement prestmt=null;
      DBstep.iDBManager2000 DbaObj=new DBstep.iDBManager2000();
      DbaObj.OpenConnection();
     
    //取得數據庫中的數據
     Sql="select  *  from  t_local_zhongzhuan ";
     result=DbaObj.ExecuteQuery(Sql);
     result.next();

     //將數據庫中的數據讀到流中
    InputStream inStream=result.getBinaryStream("content");
    FileOutputStream fs=new FileOutputStream( "c:/dffdsafd.doc");

      byte[]  buffer =new  byte[1444];
    int length;
        while ((byteread=inStream.read(buffer))!=-1)
        {
           out.println("<DT><B>"+byteread+"</B></DT>");
           bytesum+=byteread;
           System.out.println(bytesum);
       
       
           fs.write(buffer,0,byteread);
         }
    %>

    再說從服務器上下載的情形:

    <%@ page contentType="text/html; charset=gb2312" %>
    <%@ page import="java.io.*" %>
    <%
      String fileName = "zsc104.swf".toString();
    f//讀到流中
    InputStream inStream=new FileInputStream("c:/zsc104.swf");
     
    //設置輸出的格式
      response.reset();
      response.setContentType("bin");
      response.addHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
     
    //循環取出流中的數據
      byte[] b = new byte[100];
      int len;
      while((len=inStream.read(b)) >0)
      response.getOutputStream().write(b,0,len);  
      inStream.close();
    %>

       好了,到這里只要不是太大的文件的上傳下載的操作都可以完成了。

    posted @ 2007-04-13 14:10 阿偉 閱讀(316) | 評論 (0)編輯 收藏


    在頁面中先設置一個hidden來傳遞參數以便其他頁面用request.getParameter()獲得,

    hidden必須寫在窗體form中,而且另一個要得到它的頁面必須是form中的action指向的頁

    面,不然得不到。切記!!!

    posted @ 2007-04-12 18:26 阿偉 閱讀(1975) | 評論 (1)編輯 收藏

    很多網頁都是框架結構的,在很多的情況下會通過按鈕點擊事件或鏈接,跳出框架轉到其它界面。例如說點擊“注銷登錄”返回到登錄界面。

    一、通過運行腳本跳出框架有以下幾種寫法:

    1.  <script language = javascript>window.open('Login.aspx','_top')</script>"

    2.  <script language = javascript>window.open('Login.aspx','_parent')</script>"

    3. <script language = javascript>window.parent.location.href='login.aspx'</script>

    4.    Response.Write("<script>window.parent.opener=null;window.top.close();</script>")

           Response.Write("<script>window.open('index.aspx','');</script>")

           這種方法會先關閉原框架窗口,再重新打開一個新的窗口。這在很多功能界面對瀏覽器進行了改變設置,而回到登陸界面又用缺省設置的情況下適用。

    二、鏈接跳出框架

    這種情況就很簡單了,加上 target="_top" 屬性就可以了。


    posted @ 2007-04-04 13:24 阿偉 閱讀(5679) | 評論 (4)編輯 收藏

    zilong


    文章來源:http://21958978.spaces.live.com/Lists/cns!A7DF246804AD47BB!102
    posted @ 2007-03-31 10:49 阿偉 閱讀(221) | 評論 (0)編輯 收藏

    Hibernate??VS? iBATIS

    轉之ewolf的工作專欄

    簡介

    Hibernate 是當前最流行的 O/R mapping 框架,當前版本是 3.05 。它出身于 sf.net ,現在已經成為 Jboss 的一部分了

    iBATIS 是另外一種優秀的 O/R mapping 框架,當前版本是 2.0 。目前屬于 apache 的一個子項目了。

    相對 Hibernate O/R ”而言, iBATIS 是一種“ Sql Mapping ”的 ORM 實現。

    Hibernate 對數據庫結構提供了較為完整的封裝, Hibernate O/R Mapping 實現了 POJO 和數據庫表之間的映射,以及 SQL 的自動生成和執行。程序員往往只需定義好了 POJO 到數據庫表的映射關系,即可通過 Hibernate 提供的方法完成持久層操作。程序員甚至不需要對 SQL 的熟練掌握, Hibernate/OJB 會根據制定的存儲邏輯,自動生成對應的 SQL 并調用 JDBC 接口加以執行。

    iBATIS 的著力點,則在于 POJO SQL 之間的映射關系。也就是說, iBATIS 并不會為程序員在運行期自動生成 SQL 執行。具體的 SQL 需要程序員編寫,然后通過映射配置文件,將 SQL 所需的參數,以及返回的結果字段映射到指定 POJO

    使用 iBATIS 提供的 ORM 機制,對業務邏輯實現人員而言,面對的是純粹的 Java 對象,

    這一層與通過 Hibernate 實現 ORM 而言基本一致,而對于具體的數據操作, Hibernate 會自動生成 SQL 語句,而 iBATIS 則要求開發者編寫具體的 SQL 語句。相對 Hibernate 而言, iBATIS SQL 開發的工作量和數據庫移植性上的讓步,為系統設計提供了更大的自由空間。

    二者的對比:

    1. ? iBATIS 非常簡單易學, Hibernate 相對較復雜,門檻較高。

    2. ? 二者都是比較優秀的開源產品

    3. ? 當系統屬于二次開發 , 無法對數據庫結構做到控制和修改 , iBATIS 的靈活性將比 Hibernate 更適合

    4. ? 系統數據處理量巨大,性能要求極為苛刻,這往往意味著我們必須通過經過高度優化的 SQL 語句(或存儲過程)才能達到系統性能設計指標。在這種情況下 iBATIS 會有更好的可控性和表現。

    5. ? iBATIS 需要手寫 sql 語句,也可以生成一部分, Hibernate 則基本上可以自動生成,偶爾會寫一些 Hql 。同樣的需求 ,iBATIS 的工作量比 Hibernate 要大很多。類似的,如果涉及到數據庫字段的修改, Hibernate 修改的地方很少,而 iBATIS 要把那些 sql mapping 的地方一一修改。

    6. ? 以數據庫字段一一對應映射得到的 PO Hibernte 這種對象化映射得到的 PO 是截然不同的,本質區別在于這種 PO 是扁平化的,不像 Hibernate 映射的 PO 是可以表達立體的對象繼承,聚合等等關系的,這將會直接影響到你的整個軟件系統的設計思路。

    7. ? Hibernate 現在已經是主流 O/R Mapping 框架,從文檔的豐富性,產品的完善性,版本的開發速度都要強于 iBATIS

    8. ? 最關鍵的一句話是 iBATIS 的作者說的:

    If you are starting a new project and you're in full control of your object model and database design, Hibernate is a good choice of O/R tool.

    If you are accessing any 3rd party databases (e.g. vendor supplied), or you're working with a legacy database, or even just a really poorly designed database, then an O/R mapper might not be capable of handling the situation. That's were an SQL Mapper comes in handy

    ?

    結論:

    結論:

    Hibernate 和iBATIS可以說是互相補充,共同發展的關系.具體你想用什么要看實際情況.如果看了上面的文字還是拿不定注意,那就Just to try it.實踐是檢驗真理的唯一標準.鞋合不合適,只有試了才知道



    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=413018


    文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!195.entry
    posted @ 2007-03-31 10:49 阿偉 閱讀(210) | 評論 (0)編輯 收藏

    j2ee的O/R方案真是多,和Hibernate相比,iBatis最大的特點就是小巧,上手很快。看iBatis的文檔2小時就會用了,這個O/R Mapping特點就是簡單易用。只要有SQL基礎,相信你不用教程也能看明白。最新版本2.0(下載)。

    構建ibatis基礎代碼
    ibatis 基礎代碼包括:


    1. ibatis 實例配置
    一個典型的配置文件如下(具體配置項目的含義見后):
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE sqlMapConfig
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
    <sqlMapConfig>
    <settings
    cacheModelsEnabled="true"
    enhancementEnabled="true"
    lazyLoadingEnabled="true"
    errorTracingEnabled="true"
    maxRequests="32"
    maxSessions="10"
    maxTransactions="5"
    useStatementNamespaces="false"
    />
    <transactionManager type="JDBC">
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    <dataSource type="SIMPLE">
    <property name="JDBC.Driver"
    value="com.p6spy.engine.spy.P6SpyDriver"/>
    <property name="JDBC.ConnectionURL"
    value="jdbc:mysql://localhost/sample"/>
    <property name="JDBC.Username" value="user"/>
    <property name="JDBC.Password" value="mypass"/>
    <property name="Pool.MaximumActiveConnections"
    value="10"/>
    <property name="Pool.MaximumIdleConnections" value="5"/>
    <property name="Pool.MaximumCheckoutTime"
    value="120000"/>
    <property name="Pool.TimeToWait" value="500"/>
    <property name="Pool.PingQuery" value="select 1 from
    ACCOUNT"/>
    <property name="Pool.PingEnabled" value="false"/>
    <property name="Pool.PingConnectionsOlderThan"
    value="1"/>
    <property name="Pool.PingConnectionsNotUsedFor"
    value="1"/>
    </dataSource>
    </transactionManager>
    <sqlMap resource="com/ibatis/sample/User.xml"/>
    </sqlMapConfig>


    2. POJO(Plain Ordinary Java Object)
    下面是我們用作示例的一個POJO:
    public class User implements Serializable {
    private Integer id;
    private String name;
    private Integer sex;
    private Set addresses = new HashSet();
    /** default constructor */
    public User() {
    }
    public Integer getId() {
    return this.id;
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    }
    public void setId(Integer id) {
    this.id = id;
    }
    public String getName() {
    return this.name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public Integer getSex() {
    return this.sex;
    }
    public void setSex(Integer sex) {
    this.sex = sex;
    }
    }


    3. 映射文件
    與Hibernate 不同。因為需要人工編寫SQL 代碼,ibatis 的映射文件一般采
    用手動編寫(通過Copy/Paste,手工編寫映射文件也并沒想象中的麻煩)。
    針對上面POJO 的映射代碼如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE sqlMap
    PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-2.dtd">
    <sqlMap namespace="User">
    <typeAlias alias="user" type="com.ibatis.sample.User"/>
    <select id="getUser"
    parameterClass="java.lang.String"
    resultClass="user">
    <![CDATA[
    select
    name,
    sex
    from t_user
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    where name = #name#
    ]]>
    </select>
    <update id="updateUser"
    parameterClass="user">
    <![CDATA[
    UPDATE t_user
    SET
    name=#name#,
    sex=#sex#
    WHERE id = #id#
    ]]>
    </update>
    <insert id="insertUser"
    parameterClass="user"
    >
    INSERT INTO t_user (
    name,
    sex)
    VALUES (
    #name#,
    #sex#
    )
    </insert>
    <delete id="deleteUser"
    parameterClass="java.lang.String">
    delete from t_user
    where id = #value#
    </delete>
    </sqlMap>
    從上面的映射文件可以看出,通過<insert>、<delete>、<update>、
    <select>四個節點,我們分別定義了針對TUser 對象的增刪改查操作。在這
    四個節點中,我們指定了對應的SQL 語句,以update節點為例:
    ……
    <update id="updateUser" ⑴
    parameterClass="user"> ⑵
    <![CDATA[ ⑶
    UPDATE t_user ⑷
    SET (
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    name=#name#, ⑸
    sex=#sex# ⑹
    )
    WHERE id = #id# ⑺
    ]]>
    </update>
    ……

    ⑴ ID
    指定了操作ID,之后我們可以在代碼中通過指定操作id 來執行此節點所定
    義的操作,如:
    sqlMap.update("updateUser",user);
    ID設定使得在一個配置文件中定義兩個同名節點成為可能(兩個update節
    點,以不同id區分)

    ⑵ parameterClass
    指定了操作所需的參數類型, 此例中update 操作以
    com.ibatis.sample.User 類型的對象作為參數,目標是將提供的User
    實例更新到數據庫。
    parameterClass="user"中,user為“com.ibatis.sample.User”
    類的別名,別名可通過typeAlias節點指定,如示例配置文件中的:
    <typeAlias alias="user" type="com.ibatis.sample.User"/>

    ⑶ <![CDATA[……]]>
    通過<![CDATA[……]]>節點,可以避免SQL 中與XML 規范相沖突的字符對
    XML映射文件的合法性造成影響。

    ⑷ 執行更新操作的SQL,這里的SQL 即實際數據庫支持的SQL 語句,將由
    ibatis填入參數后交給數據庫執行。

    ⑸ SQL中所需的用戶名參數,“#name#”在運行期會由傳入的user對象的name
    屬性填充。

    ⑹ SQL 中所需的用戶性別參數“#sex#”,將在運行期由傳入的user 對象的
    sex屬性填充。

    ⑺ SQL中所需的條件參數“#id#”,將在運行期由傳入的user對象的id屬性
    填充。

    對于這個示例,ibatis在運行期會讀取id 為“updateUser”的update節點
    的SQL定義,并調用指定的user對象的對應getter方法獲取屬性值,并用此
    屬性值,對SQL中的參數進行填充后提交數據庫執行。
    此例對應的應用級代碼如下,其中演示了ibatis SQLMap的基本使用方法:
    String resource ="com/ibatis/sample/SqlMapConfig.xml";
    Reader reader;
    reader = Resources.getResourceAsReader(resource);
    XmlSqlMapClientBuilder xmlBuilder =
    new XmlSqlMapClientBuilder();
    SqlMapClient sqlMap = xmlBuilder.buildSqlMap(reader);
    (上面代碼調試不過可用一下代碼代替:
    Reader reader = Resources.getResourceAsReader( resource );
    ??SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);)
    //sqlMap系統初始化完畢,開始執行update操作
    try{
    sqlMap.startTransaction();
    User user = new User();
    user.setId(new Integer(1));
    user.setName("Erica");
    user.setSex(new Integer(1));
    sqlMap.update("updateUser",user);
    sqlMap.commitTransaction();
    finally{
    sqlMap.endTransaction();
    }
    其中,SqlMapClient是ibatis運作的核心,所有操作均通過SqlMapClient
    實例完成。
    可以看出,對于應用層而言,程序員面對的是傳統意義上的數據對象,而非JDBC
    中煩雜的ResultSet,這使得上層邏輯開發人員的工作量大大減輕,同時代碼更
    加清晰簡潔。
    數據庫操作在映射文件中加以定義,從而將數據存儲邏輯從上層邏輯代碼中獨立
    出來。
    而底層數據操作的SQL可配置化,使得我們可以控制最終的數據操作方式,通過
    SQL的優化獲得最佳的數據庫執行效能,這在依賴SQL自動生成的“全自動”ORM
    機制中是所難以實現的。
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    ibatis配置
    結合上面示例中的ibatis配置文件。下面是對配置文件中各節點的說明:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE sqlMapConfig
    PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
    "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
    <sqlMapConfig>
    <settings ⑴
    cacheModelsEnabled="true"
    enhancementEnabled="true"
    lazyLoadingEnabled="true"
    errorTracingEnabled="true"
    maxRequests="32"
    maxSessions="10"
    maxTransactions="5"
    useStatementNamespaces="false"
    />
    <transactionManager type="JDBC"> ⑵
    <dataSource type="SIMPLE"> ⑶
    <property name="JDBC.Driver"
    value="com.p6spy.engine.spy.P6SpyDriver"/>
    <property name="JDBC.ConnectionURL"
    value="jdbc:mysql://localhost/sample"/>
    <property name="JDBC.Username" value="user"/>
    <property name="JDBC.Password" value="mypass"/>
    <property name="Pool.MaximumActiveConnections"
    value="10"/>
    <property name="Pool.MaximumIdleConnections" value="5"/>
    <property name="Pool.MaximumCheckoutTime"
    value="120000"/>
    <property name="Pool.TimeToWait" value="500"/>
    <property name="Pool.PingQuery" value="select 1 from
    ACCOUNT"/>
    <property name="Pool.PingEnabled" value="false"/>
    <property name="Pool.PingConnectionsOlderThan"
    value="1"/>
    <property name="Pool.PingConnectionsNotUsedFor"
    value="1"/>
    </dataSource>
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    </transactionManager>
    <sqlMap resource="com/ibatis/sample/User.xml"/> ⑷
    <sqlMap resource="com/ibatis/sample/Address.xml"/>
    </sqlMapConfig>

    ⑴ Settings 節點
    參數 描述
    cacheModelsEnabled 是否啟用SqlMapClient上的緩存機制。
    建議設為"true"
    enhancementEnabled 是否針對POJO啟用字節碼增強機制以提升
    getter/setter的調用效能,避免使用Java
    Reflect所帶來的性能開銷。
    同時,這也為Lazy Loading帶來了極大的性能
    提升。
    建議設為"true"
    errorTracingEnabled 是否啟用錯誤日志,在開發期間建議設為"true"
    以方便調試
    lazyLoadingEnabled 是否啟用延遲加載機制,建議設為"true"
    maxRequests 最大并發請求數(Statement并發數)
    maxTransactions 最大并發事務數
    maxSessions 最大Session 數。即當前最大允許的并發
    SqlMapClient數。
    maxSessions設定必須介于
    maxTransactions和maxRequests之間,即
    maxTransactions<maxSessions=<
    maxRequests
    useStatementNamespaces 是否使用Statement命名空間。
    這里的命名空間指的是映射文件中,sqlMap節點
    的namespace屬性,如在上例中針對t_user
    表的映射文件sqlMap節點:
    <sqlMap namespace="User">
    這里,指定了此sqlMap節點下定義的操作均從
    屬于"User"命名空間。
    在useStatementNamespaces="true"的情
    況下,Statement調用需追加命名空間,如:
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    sqlMap.update("User.updateUser",use
    r);
    否則直接通過Statement名稱調用即可,如:
    sqlMap.update("updateUser",user);
    但請注意此時需要保證所有映射文件中,
    Statement定義無重名。

    ⑵ transactionManager節點
    transactionManager 節點定義了ibatis 的事務管理器,目前提供了以下幾
    種選擇:
    ? JDBC
    通過傳統JDBC Connection.commit/rollback實現事務支持。
    ? JTA
    使用容器提供的JTA服務實現全局事務管理。
    ? EXTERNAL
    外部事務管理,如在EJB中使用ibatis,通過EJB的部署配置即可實現自
    動的事務管理機制。此時ibatis 將把所有事務委托給外部容器進行管理。
    此外,通過Spring 等輕量級容器實現事務的配置化管理也是一個不錯的選
    擇。關于結合容器實現事務管理,參見“高級特性”中的描述。

    ⑶ dataSource節點
    dataSource從屬于transactionManager節點,用于設定ibatis運行期使
    用的DataSource屬性。
    type屬性: dataSource節點的type屬性指定了dataSource的實現類型。
    可選項目:
    ? SIMPLE:
    SIMPLE是ibatis內置的dataSource實現,其中實現了一個簡單的
    數據庫連接池機制, 對應ibatis 實現類為
    com.ibatis.sqlmap.engine.datasource.SimpleDataSourceFactory。
    ? DBCP:
    基于Apache DBCP 連接池組件實現的DataSource 封裝,當無容器提
    供DataSource 服務時,建議使用該選項,對應ibatis 實現類為
    com.ibatis.sqlmap.engine.datasource.DbcpDataSourceFactory。
    ? JNDI:
    使用J2EE 容器提供的DataSource 實現,DataSource 將通過指定
    的JNDI Name 從容器中獲取。對應ibatis 實現類為
    com.ibatis.sqlmap.engine.datasource.JndiDataSourceFacto
    ry。
    dataSource的子節點說明(SIMPLE&DBCP):
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    參數 描述
    JDBC.Driver JDBC 驅動。
    如:org.gjt.mm.mysql.Driver
    JDBC.ConnectionURL 數據庫URL。
    如:jdbc:mysql://localhost/sample
    如果用的是SQLServer JDBC Driver,需要
    在url后追加SelectMethod=Cursor以獲得
    JDBC事務的多Statement支持。
    JDBC.Username 數據庫用戶名
    JDBC.Password 數據庫用戶密碼
    Pool.MaximumActiveConn
    ections
    數據庫連接池可維持的最大容量。
    Pool.MaximumIdleConnec
    tions
    數據庫連接池中允許的掛起(idle)連接數。
    以上子節點適用于SIMPLE 和DBCP 模式,分別針對SIMPLE 和DBCP 模式的
    DataSource私有配置節點如下:
    SIMPLE:
    參數 描述
    Pool.MaximumCheckoutTi
    me
    數據庫聯接池中,連接被某個任務所允許占用的
    最大時間,如果超過這個時間限定,連接將被強
    制收回。(毫秒)
    Pool.TimeToWait 當線程試圖從連接池中獲取連接時,連接池中無
    可用連接可供使用,此時線程將進入等待狀態,
    直到池中出現空閑連接。此參數設定了線程所允
    許等待的最長時間。(毫秒)
    Pool.PingQuery 數據庫連接狀態檢測語句。
    某些數據庫在連接在某段時間持續處于空閑狀態
    時會將其斷開。而連接池管理器將通過此語句檢
    測池中連接是否可用。
    檢測語句應該是一個最簡化的無邏輯SQL。
    如“select 1 from t_user”,如果執行此語句
    成功,連接池管理器將認為此連接處于可用狀態。
    Pool.PingEnabled 是否允許檢測連接狀態。
    Pool.PingConnectionsOl
    derThan
    對持續連接時間超過設定值(毫秒)的連接進行
    檢測。
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    Pool.PingConnectionsNo
    tUsedFor
    對空閑超過設定值(毫秒)的連接進行檢測。
    DBCP:
    參數 描述
    Pool.MaximumWait 當線程試圖從連接池中獲取連接時,連接池中無
    可用連接可供使用,此時線程將進入等待狀態,
    直到池中出現空閑連接。此參數設定了線程所允
    許等待的最長時間。(毫秒)
    Pool.ValidationQuery 數據庫連接狀態檢測語句。
    某些數據庫在連接在某段時間持續處于空閑狀態
    時會將其斷開。而連接池管理器將通過此語句檢
    測池中連接是否可用。
    檢測語句應該是一個最簡化的無邏輯SQL。
    如“select 1 from t_user”,如果執行此語句
    成功,連接池管理器將認為此連接處于可用狀態。
    Pool.LogAbandoned 當數據庫連接被廢棄時,是否打印日志。
    Pool.RemoveAbandonedTi
    meout
    數據庫連接被廢棄的最大超時時間
    Pool.RemoveAbandoned 當連接空閑時間超過
    RemoveAbandonedTimeout時,是否將其廢
    棄。
    JNDI由于大部分配置是在應用服務器中進行,因此ibatis中的配置相對簡單,下面
    是分別使用JDBC和JTA事務管理的JDNI配置:
    使用JDBC事務管理的JNDI DataSource配置
    <transactionManager type="JDBC" >
    <dataSource type="JNDI">
    <property name="DataSource"
    value="java:comp/env/jdbc/myDataSource"/>
    </dataSource>
    </transactionManager>
    <transactionManager type="JTA" >
    <property name="UserTransaction"
    value="java:/ctx/con/UserTransaction"/>
    <dataSource type="JNDI">
    <property name="DataSource"
    value="java:comp/env/jdbc/myDataSource"/>
    </dataSource>
    IBATIS Developer’s Guide Version 1.0
    September 2, 2004 So many open source projects. Why not Open your Documents?
    </transactionManager>

    ⑷ sqlMap節點
    sqlMap 節點指定了映射文件的位置,配置中可出現多個sqlMap 節點,以指定
    項目內所包含的所有映射文件。

    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=669112


    文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!196.entry
    posted @ 2007-03-31 10:49 阿偉 閱讀(379) | 評論 (0)編輯 收藏
    inner join&left outer join&right outer join
    left outer join === left join
    rirht outer join === right join
    full outer join === full join
    inner join? === A = B
    ?
    no full inner join
    no left inner join
    no right inner join
    ?
    they are the same as the "inner join"
    ?
    ?
    ?
    ?
    Join types

    By default, a join is assumed to be an inner join. You can also request other types of joins by clicking Join Type on the Joins page of SQL Assist. The following types of joins are available:

    • Inner join
    • Left outer join
    • Right outer join
    • Full outer join

    7 An inner join is join method in which 7 a column that is not common to all of the tables being joined is dropped from 7 the resultant table. If your database supports the OUTER JOIN keywords, you 7 can extend the inner join to add rows from one table that have no matching 7 rows in the other table.

    For example, you want to join two tables to get the last name of the manager for each department. The first table is a Department table that lists the employee number of each department manager. The second table is an Employee table that lists the employee number and last name of each employee. However, some departments do not have a manager; in these cases, the employee number of the department manager is null. To include all departments regardless of whether they have a manager, and the last name of the manager, if one exists, you create a left outer join. The left outer join includes rows in the first table that match the second table or are null. The resulting SQL statement is as follows:

    SELECT DEPTNO, DEPTNAME, EMPNO, LASTNAME
       FROM DEPARTMENT LEFT OUTER JOIN EMPLOYEE
          ON MGRNO = EMPNO 

    A right outer join is the same as a left outer join, except that it includes rows in the second table that match the first table or are null. A full outer join includes matching rows and null rows from both tables.

    For example, you have two tables, Table 1 and Table 2, with the following data:

    Table 1. Table 1
    Column A Column B
    1 A
    2 B
    3 C
    Table 2. Table 2
    Column C Column D
    2 X
    4 2

    You specify a join condition of Column A = Column C. The result tables for the different types of joins are as follows:

    Inner join
    Table 3. Inner join result table
    Column A Column B Column C Column D
    2 B 2 X
    Left outer join
    Table 4. Left outer join result table
    Column A Column B Column C Column D
    1 A null null
    2 B 2 X
    3 C null null
    Right outer join
    Table 5. Right outer join result table
    Column A Column B Column C Column D
    2 B 2 X
    null null 4 2
    Full outer join
    Table 6. Full outer join result table
    Column A Column B Column C Column D
    1 A null null
    2 B 2 X
    3 C null null
    null null 4 2

    If you specify value (a,c), you obtain the following result:

    Table 7. Result of value (a,c)
    Value (a,c)
    1
    2
    3
    4
    Related concepts

    文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!197.entry
    posted @ 2007-03-31 10:49 阿偉 閱讀(1142) | 評論 (0)編輯 收藏
    刻錄光碟超刻方法
    [size=2]最近在學習刻盤,剛好在wuyou看到一篇“刻錄光碟如何設置超刻”,轉過來一起學習一下。
    具體方法如下:
    1.啟動NERO到如下畫面:
    [b]
    [img]http://bbs.crsky.com/1128632305/Mon_0702/6_181952_4b6f4a1db0f69cd.jpg[/img]

    2、在開始刻錄前首先需要在Nero中進行參數設置,設置方法如下:
    [b]
    [img]http://bbs.crsky.com/1128632305/Mon_0702/6_181952_4be2b6e9fb19105.jpg[/img]

    單擊菜單:文件-設置--高級屬性,按圖設置:
    [b]
    [img]http://bbs.crsky.com/1128632305/Mon_0702/6_181952_09ddc4bcc1c9789.jpg[/img]

    3、從“文件”菜單下選擇“刻錄鏡像文件”,然后單擊工具欄上的刻錄按鈕,在刻錄方式下選擇“光盤一次刻錄”選項。
    4、這時Nero會提醒光盤容量不足,不用理會,之后會出現以下提示信息,單擊“刻錄超燒光盤”按鈕開始刻錄。 接下來只要等待刻錄結束即可。[/size]
    [b]
    [img]http://bbs.crsky.com/1128632305/Mon_0702/6_181952_f6705fd32f2e2a2.jpg[/img]

    文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!198.entry
    posted @ 2007-03-31 10:49 阿偉 閱讀(310) | 評論 (0)編輯 收藏
    Nero超刻方法
    ?
    2006-10-06 22:28:58
    ?
    大中小
    中文NERO
    ??? 首先,看你的刻錄機是否支持超刻。
    ??? 打開,Nero Burning ROM,菜單:
    刻錄器>>選擇刻錄器...,或快捷鍵CTRL+R,選中刻錄機,看刻錄機屬性,如果提示是:“超燒功能:支持
    ”,那就可以超刻。有的nero版本有刻錄精靈,一定要關閉。
    ?
    ??? 然后,測試盤片最大超刻容量。
    ??? 放入CD-R,打開Nero ToolKit中的Nero CD-DVD Speed,選擇“其它”->(超刻測試...)。用它可以
    測試最大超刻容量。點擊“開始”按鈕,超刻測試開始。測試完成,軟件能把測試的最大時間(容量)以
    數據庫的形式保存起來,這個工具同時能夠檢測碟片的ATIP信息和給出碟片制造商和染料代號等信息。
    ?
    ??? 測完之后,在Nero Burning ROM菜單:
    ?首先,在菜單:
    文件->參數選項? ->專家功能
    選中Enable over burn Disk-at-once,打開超刻功能,同時寫上測試出的容量(小一點保險)
    ?其次,在文件->專輯信息(F7)->多區段,選擇無多區段。
    ?????? ->刻錄Burn,選擇關閉光盤Finalize CD,寫入模式Write Method->選擇光盤一次刻錄(Disc-At-
    Once,簡稱DAO)
    ?? 最后,進行刻錄的時候,跳出的窗口選擇“是”
    ?? 事實上,超刻與刻錄機,刻錄盤關系很大,不同的刻錄機超刻能力不一樣,一般能超刻750M。
    以上的刻錄機都會把這點專門說明,因此,你的刻錄機未必能刻出盤能達到的超刻容量。
    請謹慎行事.
    英文版NERO
    ??? 首先,看你的刻錄機是否支持超刻。
    ??? 打開,Nero Burning ROM,菜單:
    ??? Recorder>>Choose Recorder...,或快捷鍵CTRL+R,選中刻錄機,看刻錄機屬性,如果提示是
    verburn: suppored,那就可以超刻。有的nero版本有刻錄精靈,一定要關閉。
    ?
    ??? 然后,測試盤片最大超刻容量。
    ??? 放入CD-R,打開Nero ToolKit中的Nero CD-DVD Speed,選擇Extra->Overburning test...。用它可
    以測試最大超刻容量。點擊“開始”按鈕,超刻測試開始。測試完成,軟件能把測試的最大時間(容量)
    以數據庫的形式保存起來,這個工具同時能夠檢測碟片的ATIP信息和給出碟片制造商和染料代號等信息。
    ?
    ??? 測完之后,在Nero Burning ROM菜單:
    ? 首先,在菜單:
    File->Preference->Expert Features
    選中Enable over burn Disk-at-once,打開超刻功能,同時寫上測試出的容量(小一點保險)
    ? 其次,在文件File->Compilation Properties...(F7)->Multisesion,No Multisesson。
    ????????? ->Burn,選擇關閉光盤Finalize CD,寫入模式Write Method->選擇光盤一次刻錄(Disc-At-
    Once,簡稱DAO)
    ?? 最后,進行刻錄的時候,跳出的窗口選擇“是”
    ?? 事實上,超刻與刻錄機,刻錄盤關系很大,不同的刻錄機超刻能力不一樣,一般能超刻750M。
    以上的刻錄機都會把這點專門說明,因此,你的刻錄機未必能刻出盤能達到的超刻容量。
    --------------------------------------------------------------------------------------------
    名詞解釋——超刻——一般有兩個意思:
    1、超CD-R容量刻錄。比如一般的CD-R盤片容量為700MB,你想刻入710MB的數據;
    2、超速刻錄。比如你的刻錄機是52X,而你買的CD-R盤片標稱值是40X,你要用52速刻錄。
    這里的“超刻”是指第一種——超容量刻錄,最大利用CD-R盤片。
    超刻需要具備三個條件:
    1、刻錄機支持超刻;
    2、CD-R盤片支持超刻;
    3、刻錄軟件設置正確。
    所以,超刻前,要先檢測你的盤片和刻錄機是否支持;刻錄時,軟件要設置正確。
    ?
    ?

    文章來源:http://21958978.spaces.live.com/Blog/cns!A7DF246804AD47BB!199.entry
    posted @ 2007-03-31 10:49 阿偉 閱讀(721) | 評論 (0)編輯 收藏
    僅列出標題
    共8頁: 上一頁 1 2 3 4 5 6 7 8 下一頁 
    主站蜘蛛池模板: 亚洲成AV人网址| 亚洲一区二区三区亚瑟 | 精品97国产免费人成视频| 亚洲2022国产成人精品无码区 | 免费无码AV电影在线观看 | 成人A级毛片免费观看AV网站| 老外毛片免费视频播放| 亚洲精品综合一二三区在线| 久久久久久久久免费看无码| a一级爱做片免费| 亚洲一区二区三区精品视频| 亚洲午夜爱爱香蕉片| 国内精品免费麻豆网站91麻豆| 黄色一级视频免费| 亚洲精品在线网站| 亚洲人成国产精品无码| 亚州免费一级毛片| 国产免费区在线观看十分钟| 亚洲va在线va天堂成人| 国产亚洲成av人片在线观看| 国产免费人视频在线观看免费| 久久99免费视频| 羞羞漫画登录页面免费| 亚洲噜噜噜噜噜影院在线播放| 在线观看亚洲精品福利片| 久久久久久久久免费看无码| 黄色片免费在线观看| 国产精品亚洲天堂| 亚洲一线产区二线产区精华| 亚洲人成图片小说网站| 国产精品自在自线免费观看 | 亚洲av无码专区在线播放| 免费看国产精品麻豆| 久久久久国产精品免费免费搜索| 日本道免费精品一区二区| 美女露隐私全部免费直播| 久久综合久久综合亚洲| 亚洲色成人网一二三区| 久久久久久a亚洲欧洲aⅴ| 亚洲熟妇少妇任你躁在线观看无码| 最新中文字幕免费视频|