欢迎光临
我们一直在努力

一些非常有用的JAVA常用方法( 2)-JSP教程,Java基础

建站超值云服务器,限时71元/月

int cint(float stsid){
     int cint = 0;
     try{
      int stsid1 = 0;
   if(stsid > 0){
      if((stsid – (int)stsid > 0) && (stsid – (int)stsid != 0.5))
         stsid1 = (int)(stsid + 0.5);
      if(stsid – (int)stsid == 0.5){
      if(((int)(stsid-0.5))%2 == 0)
         stsid1 = (int)(stsid – 0.5);
      else
            stsid1 = (int)(stsid + 0.5);
      }
            if(stsid – (int)stsid ==0)
      stsid1 = (int)stsid;
   }else{
      stsid = -stsid;
   if((stsid – (int)stsid > 0) && (stsid – (int)stsid != 0.5))
         stsid1 = – (int)(stsid + 0.5);
      if(stsid – (int)stsid == 0.5){
      if(((int)(stsid-0.5))%2 == 0)
         stsid1 = – (int)(stsid – 0.5);
      else
            stsid1 = – (int)(stsid + 0.5);
      }
            if(stsid – (int)stsid ==0)
      stsid1 = – (int)stsid;
   }
   cint = stsid1;
  }catch(exception e){}
  return cint;
  }

long clng(float numb){
     int nu = 0;
     long clng = 0;
     try{
        nu = cint(numb);
        clng = (long) nu;
     }catch(exception e){}
     return clng;
}

float dealfloat(string s){
    s=dealnull(s);
    if (s.equals(""))
return 0;
    return float.parsefloat(s);
}

string[] split(string source,string div){
      int arynum = 0,intidx=0,intidex=0,div_length = div.length();     
      if(source.compareto("")!=0){      
        if(source.indexof(div)!=-1){       
         intidx = source.indexof(div);        
         for(int intcount =1 ; ; intcount++){        
           if(source.indexof(div,intidx+div_length)!=-1){
             intidx= source.indexof(div,intidx+div_length);
             arynum = intcount;
             }
           else {arynum+=2;break;}
            }                    
       }else arynum =1;
      }else arynum = 0;
     
      intidx=0;
      intidex=0;
      string[] returnstr = new string[arynum];
     
      if(source.compareto("")!=0){
      
       if(source.indexof(div)!=-1){
       
        intidx = (int)source.indexof(div);
        returnstr[0]= (string)source.substring(0,intidx);
      
        for(int intcount =1 ; ; intcount++){
           if(source.indexof(div,intidx+div_length)!=-1){
             intidex=(int)source.indexof(div,intidx+div_length);
             
             returnstr[intcount] = (string)source.substring(intidx+div_length,intidex);
             
             intidx = (int)source.indexof(div,intidx+div_length);
             }
           else {
                returnstr[intcount] = (string)source.substring(intidx+div_length,source.length());
                break;
                }
            }
      }
      else {returnstr[0] = (string)source.substring(0,source.length());return returnstr;}
     }
     else {return returnstr;}                  
    return returnstr;    
}

public class stc_rsyb_name
  {
    public int pos = -1;
    public string name = "";
    public string host = "";
    public string home1 = "";
    public string home2 = "";
    public string home3 = "";
  }
  public class stc_syb_inf
  {
    string reg_name  = "";
    string g_syb = "";
    string r_syb = "";
  }
file://输出空格
void showblank(int num,jspwriter out){
try{
for(int i=0;i<=num;i++)
  out.print(" ");
}
catch(exception e){}  
}

   string g_syb_mk(){
     string g_syb_mk = null;
     string nis_m_o = "1???????????????????????????????????????????????????????????????";
  string local_m = "?1??????????????????????????????????????????????????????????????";
  string winnt_dc = "????1???????????????????????????????????????????????????????????";
  string nis_local = "11??????????????????????????????????????????????????????????????";
  int ret = 0,reccount = 0,k = 0;
  string set_ret = "ssy";
  string[] domein = null;
  string[] group_syb = null;
  int wk_syb[];
  try{
    string sql = "select count(*) from 寁嶼婡 where 话兽庬暿 like "+ nis_m_o +" or 话兽庬暿 like " + local_m +" or 话兽庬暿 like "+winnt_dc +"";
    rs = stmt.executequery(sql);
    if(rs.next()){
      reccount = rs.getint(1);
   rs = null;
    }
    string sql2 = "select * from 寁嶼婡 where 话兽庬暿 like "+ nis_m_o +" or 话兽庬暿 like " + local_m +" or 话兽庬暿 like "+winnt_dc +"";
    while(rs.next()){
      int i = 0;
         domein[i] = rs.getstring("霓也輺?);
   i++;
    }
    for(int j = 0 ; j < reccount ; j++){
      string sql3 = "select * from 僌儖乕僾庬暿 where 霓也輺?= " + domein[j] +"";
   rs = stmt.executequery(sql3);
   if(rs.next()){
     k = k + 1;
     group_syb[k] = rs.getstring("皋侔踢庬暿");
   }
    }
    for(int l = 0; l < 32; l++){
      for(int m = 0; m < k; m++){
     if(group_syb[m].substring(l,l+1).equals("1")){
       if(l==1){
      set_ret = "1";
    }else{
      set_ret = set_ret +  "1";
    }
    break;
     }else{
       if(m==k){
      if(l==1){
        set_ret = "0";
      }else{
        set_ret = set_ret + "0";
      }
    }
     }
   }
    }
    g_syb_mk = set_ret;
  }catch(exception e) { }
   return  g_syb_mk;
  }

int recount(string strtable,string sel)
{
string myst="";
int t = 0;
resultset rsd=null;
try
{
  myst= "select count(*) ads from " + strtable  + " " + sel;
  rsd= conn.createstatement().executequery(myst);
  if (rsd.next())
  {
   t=rsd.getint("ads");
  }
}
catch(sqlexception sqe)
{
  system.out.println("odbc wrong :" + sqe +"+" +myst);
}
rsd = null;
return t;

}

int dcount(string duan,string strtable,string strsel)
{
int t=0;
resultset rss=null;
try
{
  string mysql="select count(*) ads from "  + strtable + " where " + strsel + " and "+ duan +" is not null ";
  rss= conn.createstatement().executequery(mysql);
  if (rss.next())
  {
   t=rss.getint("ads");
  }
}
catch(exception sqe)
{
  system.out.println(sqe);
}
rss=null;
return t;
}

string dlookup(string duan,string strtable,string strsel)
{
        string strreturn = null;
resultset rss = null;
try{
              string strsql = "select "+duan+" from "+strtable+" where "+ strsel;
       rss = conn.createstatement().executequery(strsql);
       if(rss.next()){
             
       strreturn = rss.getstring(duan);
       }
  
}catch(java.sql.sqlexception sqle){
     system.out.println("dlookup_exception:"+sqle);
}

        rss = null;
return strreturn;
}
string rtrim(string str){
     string rstr = str;
  if(str == null)
         {
    rstr = "";
  }
         else
         {
    if(str.length() == 0) rstr = "";
    if(str.length() > 0)
    {
      for(int i = str.length() ; i  >  0 ; i–)
             {
     if(str.substring(i-1,i).equals(" "))  
       rstr = rstr.substring(0,i-1);
     else break;
   }
     }
       
  }
  return rstr;
   }
void sybinf_set(stc_rsyb_name in_data, stc_syb_inf out_data) throws java.sql.sqlexception{
    string new_syb = "00000000000000000000000000000000";
    out_data.reg_name = in_data.name;
    string sql = "";
    string rdomein1 = "";
    string rdomein2 = "";
    string rdomein3 = "";
    resultset rsf = null;
    statement stf = conn.createstatement();
    try {
      sql = "select 皋侔踢庬暿 from 僌儖乕僾庬暿 where 霓也輺?= " + in_data.host + "";
      rsf = conn.createstatement().executequery(sql);
      if (rsf.next()) {
        out_data.g_syb = dealnull(rsf.getstring("皋侔踢庬暿"));
      } else {
        out_data.g_syb = "";
      }
    } catch(java.sql.sqlexception sqle) {
      system.out.println("111111" + sqle);
    }
    try {
      sql = "select 棙梡庬暿 from 棙梡庬暿 where 霓也輺?= " + in_data.home1 + "";
      rsf = stf.executequery(sql);
      if (rsf.next())
        rdomein1 = dealnull(rsf.getstring("棙梡庬暿"));
    } catch(java.sql.sqlexception sqle) {
      system.out.println("22222" + sqle);
    }
    try {
      sql = "select 棙梡庬暿 from 棙梡庬暿 where 霓也輺?= " + in_data.home2 + "";
      rsf = stf.executequery(sql);
      if (rsf.next())
        rdomein2 = dealnull(rsf.getstring("棙梡庬暿"));
    } catch(java.sql.sqlexception sqle) {
      system.out.println("333333" + sqle);
    }
    try {
      sql = "select 棙梡庬暿 from 棙梡庬暿 where 霓也輺?= " + in_data.home3 + "";
      rsf = stf.executequery(sql);
      if (rsf.next())
        rdomein3 = dealnull(rsf.getstring("棙梡庬暿"));
    } catch(java.sql.sqlexception sqle) {
      system.out.println("444444" + sqle);
    }
    rsf = null;
    stf = null;
    string p = char_or(rdomein1, rdomein2);
    if (p.equals("")) p = new_syb;
    string q = char_or(p, rdomein3);
    if (q.equals("")) q = new_syb;
    out_data.r_syb = q;
  }
  string char_or(string arg1, string arg2) {
    int len1 = -1, len2 = -1, max_len = -1, min_len = -1;
    string ret_sts = "";
    int long_f = -1;
    len1 = arg1.length();
    len2 = arg2.length();
    if (len1 == 0 && len2 > 0)
      return arg2;
    else if (len1 > 0 && len2 == 0)
      return arg1;
    else if (len1 == 0 && len2 == 0)
      return "";
    ret_sts = "";
    if (len1 > len2) {
      max_len = len1;
      min_len = len2;
      long_f = 1;
    } else if (len1 < len2) {
       max_len = len2;
       min_len = len1;
       long_f = 2;
    } else {
       max_len = len1;
       min_len = len2;
       long_f = 0;
    }
    for (int i = 1; i <= max_len; i++) {
      if (i <= min_len) {
        if (arg1.substring(i-1, i).equals("1") || arg2.substring(i-1, i).equals("1"))
          ret_sts = ret_sts + "1";
        else
          ret_sts = ret_sts + "0";
      } else {
        if (long_f == 1)
          ret_sts = ret_sts + arg1.substring(i-1, i);
        else if (long_f == 2)
          ret_sts = ret_sts + arg2.substring(i-1, i);
      }
    }
    return ret_sts;
  }
%>

<%!
void writefile(string mystring,string target_file){
     try {
   java.io.printwriter pw = new java.io.printwriter(new java.io.fileoutputstream(target_file));
   pw.println(mystring);
   pw.close();
   mystring="";
   } catch(java.io.ioexception e) {
     system.out.println(e.getmessage());
}
  }
%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一些非常有用的JAVA常用方法( 2)-JSP教程,Java基础
分享到: 更多 (0)