⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdbcache.java

📁 队列调度算法的一种
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     for (int m=0;m<31;m++)
     {
    System.out.print(ResultArray3[k][m]);
     }
  System.out.println();
  }*/
    rs.close();
    return ResultArray3;
  }
  catch(SQLException e)
  {
    System.out.println("error message:" + e.getMessage());
    return ResultArray3;
  }
     }
     else
     {
         String[][] ResultArray4=new String[1][31];
         for(int i=0;i<31;i++)
         {
         ResultArray4[0][0]="Unknown";
         }
         return ResultArray4;

     }
   }
   
   /**
    * @version
    * @return
    * @exception
    * @author
    * @roseuid 40696A380068
    */
   public CDBCache() 
   {
  String strDbDriver=null; //驱动程序放在d:/program/org/gjt/mm/mysql里面,gjt
  String strDBUrl=null;//用户名和 密码是默认的吧?
  Connection conn =null;
  ResultSet rs = null;
  int age=0;
  String name=null;
   }
   
   /**
    * @param fields
    * @param indexName
    * @param tableName
    * @return void
    * @exception
    * @author
    * @version
    * @roseuid 4074B28E0155
    */
   public void DBCreateIndex(String fields, String indexName, String tableName) 
   {
     String strSql=null;
    try
    {
      Statement stmt = conn.createStatement();
      strSql = " create index "+indexName+" on "+tableName+"("+fields+");";
      stmt.executeUpdate(strSql);
      stmt.close();
    }
    catch(SQLException e)
    {
      System.out.println("error message:" + e.getMessage());
    }
   }
   
   /**
    * @param Time
    * @param TableName
    * @return boolean
    * @exception
    * @author
    * @version
    * @roseuid 4083D2AA0000
    */
   public boolean DBUpdate(String upColumnName, String upColumnValue, String strColumnName, String strColumnValue, String TableName) 
   {
     try
     {
       Statement stmt = conn.createStatement();
       String strSql = "Update "+ TableName+" set "+upColumnName+"="+upColumnValue+" where "+
                     strColumnName+"="+"\""+strColumnValue+"\"" ;
       stmt.executeUpdate(strSql);
       stmt.close();
       return true;
     }
     catch(SQLException e)
     {
      System.out.println("error message:" + e.getMessage());
      return false;
     }
   }
   
   /**
    * @param strTableName
    * @return boolean
    * @exception
    * @author
    * @version
    * @roseuid 4083D3C00197
    */
   public boolean DBReplace(String strTableName) 
   {
    String strSql=null;
    int count=0;
    try
    {
       Statement stmt = conn.createStatement();
       /////////
       strSql="select count(*) from "+strTableName;
       rs = stmt.executeQuery(strSql);
       while (rs.next())
       {
         count=rs.getInt("count(*)");
       }
       rs.close();
       /////
       if(MAXROWCOUNT<=count)
       {
        int delnum=count-MAXROWCOUNT+(MAXROWCOUNT*percent)/100;
        int i=0;
        String[] delarray=new String[delnum];
        strSql="select CacheFileName from "+strTableName+" order by P asc limit "+Integer.toString(delnum);
        rs = stmt.executeQuery(strSql);
        while (rs.next())
        {
          delarray[i]=rs.getString("CacheFileName");
          i++;
        }
        rs.close();
        ////
        for(int j=0;j<delnum;j++)
        {
        strSql="delete from "+strTableName+" where CacheFileName= "+"\""+delarray[j]+"\"";
        stmt.executeQuery(strSql);
        }

        //同步删除文件
        File myfile = new File("e:\\cachefile");
        for(int c1=0;c1<delnum;c1++)
        {
          File file1=new File(myfile,delarray[c1]);
          System.out.println(file1.exists());
          //删除文件
          file1.delete();
          System.out.println(file1.exists());
        }
       }
       stmt.close();
       return true;
    }
    catch(SQLException e)
    {
      System.out.println("error message:" + e.getMessage());
      return false;
    }
   }
   
   /**
    * @param strTimestamp
    * @param ColumnName
    * @param ColumnValue
    * @param TableName
    * @return Timestamp
    * @exception
    * @author
    * @version
    * @roseuid 40847977037B
    */
   public Timestamp DBGetTimeStamp(String strTimestamp, String ColumnName, String ColumnValue, String TableName) 
   {
    String strSql= null;
    Timestamp times=null;
    try
    {
      Statement stmt = conn.createStatement();
      strSql = "select "+strTimestamp+" from " +TableName+" where "+ColumnName+"="+"'"
             +ColumnValue+"';";
      rs = stmt.executeQuery(strSql);
      while (rs.next())
      {

         times=rs.getTimestamp(strTimestamp);
      }
      rs.close();
      stmt.close();
      return times;
    }
    catch(SQLException e)
    {
      System.out.println("error message:" + e.getMessage());
      return times;
    }
   }
   
   /**
    * @param strColumnName
    * @param strColumnValue
    * @param strTableName
    * @return ComParaSet
    * @exception
    * @author
    * @version
    * @roseuid 4084A29D00CC
    */
   public ComParaSet DBGetComPara(String strColumnName, String strColumnValue, String strTableName) 
   {
     String strSql= null;
     ComParaSet comparas=new ComParaSet();
    try
    {
      Statement stmt = conn.createStatement();
      strSql = "select CacheFileSize,LastUsedTime,CacheSavedCost,P  from " +strTableName+" where "+strColumnName+"="+"'"
             +strColumnValue+"';";
      rs = stmt.executeQuery(strSql);
      while (rs.next())
      {

         comparas.CacheFileSize=rs.getInt("CacheFileSize");
         comparas.LastUsedTime=rs.getTimestamp("LastUsedTime");
         comparas.CacheSavedCost=rs.getInt("CacheSavedCost");
         comparas.P=rs.getFloat("P");
      }
      rs.close();
      stmt.close();
      return comparas;
    }
    catch(SQLException e)
    {
      System.out.println("error message:" + e.getMessage());
      return comparas;
    }
   }
   
   /**
    * @param strCacheFileName
    * @param strTableName
    * @return boolean
    * @exception
    * @author
    * @version
    * @roseuid 4084B9140281
    */
   public boolean DBUpdateTimestamp(String strCacheFileName, String strTableName) 
   {
     try
     {
       Timestamp times=null;
       long tk=0;
       int count=0;
       Statement stmt = conn.createStatement();
       String strSql = "update "+ strTableName+" set LastUsedTime5 = LastUsedTime4,"+
                       "LastUsedTime4=LastUsedTime3,LastUsedTime3=LastUsedTime2,LastUsedTime2=LastUsedTime1,LastUsedTime1= null,"+
                       "CacheUsedCount= CacheUsedCount+1  where CacheFileName="+"\""+strCacheFileName+"\"";
       stmt.executeUpdate(strSql);
       strSql="select CacheUsedCount  from "+strTableName+" where CacheFileName="+"\""+strCacheFileName+"\"";
       rs = stmt.executeQuery(strSql);
       while (rs.next())
       {
         count=rs.getInt("CacheUsedCount");
       }
       rs.close();

       if(count>=5)
       strSql="select LastUsedTime5 from "+strTableName+" where CacheFileName="+"\""+strCacheFileName+"\"";
       else if(count<5)
             strSql="select LastUsedTime"+Integer.toString(count)+" from "+strTableName+" where CacheFileName="+"\""+strCacheFileName+"\"";
       rs = stmt.executeQuery(strSql);
       while (rs.next())
       {
         if(count>=5)
         times=rs.getTimestamp("LastUsedTime5");
           else if(count<5)
                times=rs.getTimestamp("LastUsedTime"+Integer.toString(count));
        //String strTemp=times.toString();
       }
       tk=ParseX.ParseTime(times);
       rs.close();

       strSql="update "+strTableName+" set LastUsedTimeLong="+Long.toString(tk)+" where CacheFileName="+"\""+strCacheFileName+"\"";;
       stmt.executeQuery(strSql);
       stmt.close();
       return true;
     }
     catch(SQLException e)
     {
      System.out.println("error message:" + e.getMessage());
      return false;
     }
   }
   
   /**
    * @param strTableName
    * @return boolean
    * @exception
    * @author
    * @version
    * @roseuid 4084B98B0271
    */
   public boolean DBUpdateP(String strTableName) 
   {
     try
     {
       long x=System.currentTimeMillis();
       Timestamp times=new Timestamp(x);
       long t=ParseX.ParseTime(times);

       //long t1=ParseX.ParseTime(LastUsedTime);
       //float labuda=1/(t-t1);
       //System.out.println(t);
       Statement stmt = conn.createStatement();
       String strSql = "update "+strTableName+" set LastUsedTime1=LastUsedTime1, P="+Integer.toString(K)+"*10000000*CacheSavedCost/(("+Long.toString(t)+"-"+
                       "LastUsedTimeLong"+")*"+"CacheFileSize"+")" +" where CacheUsedCount>="+Integer.toString(K);
       stmt.executeUpdate(strSql);
       strSql="update "+strTableName+" set LastUsedTime1=LastUsedTime1, P="+"CacheUsedCount*10000000*CacheSavedCost/(("+Long.toString(t)+"-"+
                       "LastUsedTimeLong"+")*"+"CacheFileSize"+")" +" where CacheUsedCount<"+Integer.toString(K);
       stmt.executeUpdate(strSql);
       stmt.close();
       return true;
     }
     catch(SQLException e)
     {
      System.out.println("error message:" + e.getMessage());
      return false;
     }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -