有如下代码:// 随机生成并初始化数据
public void init()
{
  preClose = 1000+Math.random() * 1500; // 初始化昨日收盘指数
  max = preClose;
  min = preClose;
  for (int i = 0; i < counter; i++)
  {
    if (i == 0)
    {
      if (Math.random() > 0.5)
        yPoint[i] = preClose + Math.random() * 10;
      else
        yPoint[i] = preClose - Math.random() * 10;      volume[i] = (int)(10000 * (1+Math.random() * 5));
    }
    else
    {
      if (Math.random() > 0.5)
      {
        if ((yPoint[i - 1] + Math.random() * 3) >= preClose * 1.018)
          yPoint[i] = yPoint[i - 1] - Math.random() * 3;
        else
          yPoint[i] = yPoint[i - 1] + Math.random() * 3;
      }
      else
      {
        if ((yPoint[i - 1] - Math.random() * 3) <= preClose * 0.982)
          yPoint[i] = yPoint[i - 1] + Math.random() * 3;
        else
          yPoint[i] = yPoint[i - 1] - Math.random() * 3;
      }      if (Math.random() > 0.5)
        volume[i] = volume[i - 1] + (int)(Math.random() * 10000);
      else
        volume[i] = volume[i - 1] - (int)(Math.random() * 10000);      if (volume[i] >= 100000)
        volume[i] -= 10000+(int)(Math.random() * 5000);      if (volume[i] <= 10000)
        volume[i] += 10000+(int)(Math.random() * 5000);
    }
    if (i == 0)
    {
      open = yPoint[i];
    }
    else if (i == counter - 1)
    {
      close = yPoint[i];
    }如何使得// 随机生成并初始化数据 这一块变成从mysql 数据库中读取数据并且使用数据库中数据绘制呢?请高手们指教啊,谢谢了,分不多了,就10分了啊~!

解决方案 »

  1.   

    你是不知道怎么从mysql 数据库中读取数据?
      

  2.   

    连接mysql 数据库已经搞定了这个时候要从mysql中取出数据 比如 date字段 的数据 
    在上面语句该如何写呢?
    请指教啊 谢谢!
      

  3.   

    把那个字段用select filename from tab where ..语句选出来!
    然后用  Float var=new Float(rs.getString("filename "));
            float fl=var.floatvalue();
    然后在你的程序里面使用那个时间变量就可以liao!
      

  4.   

    // 随机生成并初始化数据
    public void init()
    {
      preClose = 1000+Math.random() * 1500; // 初始化昨日收盘指数
      max = preClose;
      min = preClose;
    这里应该怎么写呢?直接写成?
    public void init()
    {
            select filename from tab where ```````````
            Float var=new Float(rs.getString("filename "));
            float fl=var.floatvalue();
      preClose = 1000+Math.random() * 1500; // 初始化昨日收盘指数
      max = preClose;
      min = preClose;
      

  5.   

    这样有错误哦~sql="select data from ecgfile where systime='systime'";
            Float var=new Float(rs.getString("filename "));
            float fl=var.floatvalue();还请 Sunny319 再详细指点下呀,谢谢了
      

  6.   

    Connection cn = null;
            PreparedStatement st = null;
            ResultSet rset = null;
            float fl=0;
            cn=/*你取得数据库连接的函数代码*/;
            st = cn.prepareStatement("select data from ecgfile where systime=?");
            st.setString(1,systime);/*设置这个参数的值*/
            rset=st.executeQuery();
            if(rset.next())
            {
                Float var=new Float(rs.getString(1));/*取得你从数据库查询的字段的值*/
                fl=var.floatvalue();
             }
            然后在后面代码就可以使用fl代码了.
      

  7.   

    我改成
    public void init()
    {
    Connection cn = null;
            PreparedStatement st = null;
            ResultSet rset = null;
            float fl=0;
            cn=DataBaseConnection.getConnection();
            st = cn.prepareStatement("select data from ecgfile where systime=?");
            st.setString(systime);
            rset=st.executeQuery();
            if(rset.next())
            {
              float var=new float(rs.getString(systime));// 这一行的 new 后的float后面提示有错误 :invalid classtype
                fl=var.floatvalue();
             }
             
    preClose = 1000+var.floatvalue() * 1500; 
    max = preClose;
    min = preClose;
    有一个错误 在float 
    是哪错了啊?
    还有就是 st.setString(1,systime);/*设置这个参数的值*/  为什么 要写个1呢?
      

  8.   

    float --->Float;F是大写的!注意.
    st = cn.prepareStatement("select data from ecgfile where systime=?");
    对上面的那个"?"参数设置值.st.setString(1,systime);1就是对第一个问号参数设置值.
      

  9.   

    哦 谢谢你啊 Sunny319!
    正是有众多像你这样热心帮助别人的人,这个论坛才能这样火!
    再一次谢谢!