zoukankan      html  css  js  c++  java
  • jsp 数据饼图

    引用:http://www.andjava.com/a/tab2/tab2_9/2012/0302/1628.html


    <%@pagelanguage="Java"%>
    <%@pageimport="java.io.OutputStream"%>
    <%@pageimport="java.sql.*"%>
    <%@pageimport="java.awt.*"%>
    <%@pageimport="java.awt.geom.*"%>
    <%@pageimport="java.awt.image.BufferedImage"%>
    <%@pageimport="com.sun.image.codec.jpeg.*"%>
    <%!
    ////////////////////////////////////////////////////////////
    //PieColorsclassmanagesthecolorsusedinthepiechart
    ////////////////////////////////////////////////////////////
    classPieColors
    {
     ColorpieColorArray[]={
      newColor(210,60,60),newColor(60,210,60),newColor(60,60,210),
      newColor(120,60,120),newColor(60,120,210),newColor(210,120,60)
      };
     intcurPieColor=0;
     publicColorgetPieColor()
     {
      returnpieColorArray[curPieColor];
     }
     publicvoidsetNewColor()
     {
      curPieColor ;
      if(curPieColor>=pieColorArray.length)
      {curPieColor=0;}
     }
    }
    %>
    <%!Stringdriver="com.MySQL.JDBC.Driver";Stringdburl="jdbc:mysql://localhost/articles";Stringdbuid="myuid";Stringdbpwd="mypwd";

    ////////////////////////////////////////////////////////////
    //GettheproductsfromthedatabaseasaStringarray
    ////////////////////////////////////////////////////////////
    publicString[]getProducts()
    {
     String[]arr=newString[0];
     Connectioncon;
     Statementstmt;
     ResultSetrs;
     intcount=0;
     Stringsql="select*fromp_productsorderbyproductID";
     try
     {
      //LoadDriver:
      Class.forName(driver);
      //Connecttothedatabasewiththeurl
      con=DriverManager.getConnection(dburl,dbuid,dbpwd);
      stmt=con.createStatement();
      //GetResultSet
      rs=stmt.executeQuery(sql);
      //Counttherecords
      while(rs.next()){count ;
     }
     //Createanarrayofthecorrectsize
     arr=newString[count];
     //GetResultSet(themostportablewayofusingrsasecondtime)
     rs=stmt.executeQuery(sql);
     while(rs.next())
     {
      arr[rs.getInt("productID")]=rs.getString("productname");
     }
     stmt.close();
     con.close();
    }
     catch(java.lang.Exceptionex)
     {arr[0]=ex.toString();}
     returnarr;
    }
    ////////////////////////////////////////////////////////////
    //Getthesalestotalsfromthedatabase
    ////////////////////////////////////////////////////////////
    publicfloat[]getSales(intproducts)
    {
     float[]arr=newfloat[products];
     Connectioncon;
     Statementstmt;
     ResultSetrs;
     Stringsql="selectproductID,amountfromp_sales";
     try{
      //LoadDriver:
      Class.forName(driver);
      //Connecttothedatabasewiththeurl
      con=DriverManager.getConnection(dburl,dbuid,dbpwd);
      stmt=con.createStatement();
      //GetResultSet
      rs=stmt.executeQuery(sql);
      while(rs.next()){intproduct=rs.getInt("productID");
      //CheckthattheproductIDisvalid
      if(product>=0&&product<products)
      {
       //Addtoproducttotal
       arr[product] =rs.getFloat("amount");
      }
     }
     stmt.close();
     con.close();
    }catch(java.lang.Exceptionex){arr[0]=-1.0f;}

  • 相关阅读:
    ACM: POJ 1401 Factorial-数论专题-水题
    ACM:POJ 2739 Sum of Consecutive Prime Numbers-素数打表-尺取法
    ACM: HDU 1028 Ignatius and the Princess III-DP
    ACM: HDU 2563 统计问题-DFS+打表
    ACM: How many integers can you find-数论专题-容斥原理的简单应用+GCD
    ACM: Happy 2004-数论专题-因子求和-快速幂
    ACM:a^b%p-数论-快速幂-快速乘
    ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
    POJ 1472 Instant Complexity 应该叫它编程题。。
    POJ 3393 Lucky and Good Months by Gregorian Calendar 模拟题
  • 原文地址:https://www.cnblogs.com/sode/p/2606270.html
Copyright © 2011-2022 走看看