甘先生Blog

          生活就像一盒巧克力,你永遠不知道你會得到什么

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            59 Posts :: 29 Stories :: 186 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(16)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

            數據庫表:tblMobile.sql
          建立一個簡單的測試表。
          create table tblMobile (id int, name varchar(20), price decimal(10,2), image varchar(50), categoryid varchar(20)) ;
          insert into tblMobile(1,'hello',200,'1.jpg','moto');



          這里利用一個jsp文件生成xml文件。
          phonelist.jsp



          <?xml version="1.0" encoding="utf-8"?> 
          <%@ page contentType="text/html;charset=utf-8"%> 
          <%@ page import="java.sql.*"%> 
          <phonelist> 
          <% 
              String sql 
          = ""
              String url 
          = ""
           
              String categoryID 
          = request.getParameter("categoryID"); 
               
              
          try 


                  Class.forName(
          "org.hsqldb.jdbcDriver").newInstance();
                  String URL
          ="jdbc:hsqldb:hsql://localhost/xdb";
                  String user
          ="sa";
                  String password
          ="";
                  Connection conn 
          = DriverManager.getConnection(URL,user,password);

                  
                  Statement stmt 
          = conn.createStatement(); 
           
                   
                  String strOut 
          = new String(categoryID.getBytes("ISO8859-1"), "GBK");  
           
                  System.out.println(
          "categoryID="+categoryID); 
                  System.out.println(
          "categoryID="+strOut); 
           
                  sql 
          = "select id, name, price, image from tblMobile where categoryid='" + strOut + "'"
                  ResultSet rs 
          = stmt.executeQuery(sql); 
           
                  
          while (rs.next())
                      out.println(
          "<phone id=\"" + rs.getString(1) + "\">"); 
                      out.println(
          "<id>" + rs.getString(1+ "</id>"); 
                      out.println(
          "<name>" + rs.getString(2+ "</name>"); 
                      out.println(
          "<price>" + rs.getString(3+ "</price>"); 
                      out.println(
          "<image>" + rs.getString(4+ "</image>"); 
                      out.println(
          "</phone>"); 
                  }
           
           
                  rs.close(); 
                  stmt.close(); 
                  conn.close(); 
           
              }
           catch (Exception e) 
                  out.println(e); 
              }
           
          %> 
          </phonelist> 


          test.lzx

          <canvas height="100" width="500" >
            
          <dataset name="myData" autorequest="true" type="http" src="phonelist.jsp?categoryID=moto"/>

            
          <simplelayout axis="y"/>

              
          <view datapath="myData:/phonelist/phone">
                  
          <simplelayout axis="x"/>
                
          <text datapath="image/text()" /> 
                
          <text datapath="name/text()" />
              
          </view>

          </canvas>



          posted on 2005-11-28 09:59 甘先生 閱讀(1542) 評論(2)  編輯  收藏 所屬分類: JavaRIA
          主站蜘蛛池模板: 滕州市| 右玉县| 鹤山市| 通城县| 潞城市| 阳曲县| 密云县| 石阡县| 丹阳市| 阆中市| 蛟河市| 正阳县| 凭祥市| 临潭县| 洛川县| 罗城| 准格尔旗| 固阳县| 辛集市| 科尔| 阿坝县| 驻马店市| 洞头县| 吉木萨尔县| 崇明县| 毕节市| 奉化市| 高清| 怀集县| 阜新市| 南木林县| 莫力| 延吉市| 仁怀市| 灯塔市| 新泰市| 拉萨市| 宁强县| 延吉市| 清水河县| 玉山县|