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;}

  • 相关阅读:
    ShellExecuteEx 函数说明
    npm
    Byte和char
    如何高效阅读一个项目
    C++中慎用malloc
    #ifdef
    string
    C++与C混合编译
    git@github.com: Permission denied (publickey).
    connect to host github.com port 22: Connection refused
  • 原文地址:https://www.cnblogs.com/sode/p/2606270.html
Copyright © 2011-2022 走看看