字符串的索引超过了字符串的长度

解决方案 »

  1.   

    忘了一点,我在:UltraEdit中可以编译通过,代码如下:
    package rongji.dagl;
    import java.sql.SQLException;
    import javax.servlet.http.HttpServletRequest;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.lang.*;public class DaWjFi extends DaWj {
      private int count;
      private String  fieldname;
      private int fieldlen;
      public DaWjFi() {
      }
      //归档,同时生成档号
     public boolean archive(int wj_id)  throws Exception{
           String  wj_dh="";
           String  fieldname,fieldvalue="";
           int     fieldlen;
           int     fieldorder;
           String  fielddivision,flh,qxdm;
           int     ys;
           String  columnname,columntype,wj_flag;
        try{
             getConnect();
             st=conn.createStatement();
             sql="select count(*) as count1 from da_wj_se where wj_id="+wj_id;
             rs=st.executeQuery(sql);
             rs.next();
             count=rs.getInt("count1");
             if ( count==0) {
                errmessage="对不起,该文件已经归档!";
                return false;
                      }         sql="select Class_id,Wj_save_timelimit,Wj_pagecount,wj_flag  as flh,qxdm,ys,wj_flag  from da_wj_gd where wj_id="+wj_id;
                rs=st.executeQuery(sql);
                rs.next();
                flh=rs.getString("flh");
                qxdm=rs.getString("qxdm");
                ys=rs.getInt("ys");
                wj_flag=rs.getString("wj_flag");
                //对归档条件进行判断 发文全部归档  收文归档条件 flh ,qxdm,ys
                if ((wj_flag=="S")&&(flh==null||qxdm==null||ys==0))
                {
                 errmessage="对不起,文件不满足归档条件请检查!";
                 return  false;
                }
                //插入数据
                sql="insert into da_wj_sc(wj_id,wj_no,wj_dury_company,wj_formdate,wj_wjno,wj_kind,wj_ywflag,wj_title,wj_subjectword,wj_projectname,wj_urgency,wj_secret,wj_fjno,class_id,wj_save_timelimit,wj_pagecount,wj_comment,wj_registerdate,wj_add_user,wj_flag,depart_id)  (select wj_id,wj_no,wj_dury_company,wj_formdate,wj_wjno,wj_kind,wj_ywflag,wj_title,wj_subjectword,wj_projectname,wj_urgency,wj_secret,wj_fjno,class_id,wj_save_timelimit,wj_pagecount,wj_comment,wj_registerdate,wj_add_user,wj_flag,depart_id from da_wj_gd where wj_id=" + wj_id+")";
                st.executeQuery(sql);
                //更改da_wj_th中的归档标志
                sql="update  da_wj_th set wj_archiveflag = '1'  where wj_id"+wj_id;
                st.executeUpdate(sql);
               //删除归档后da_wj_th中的记录
               sql="delete da_wj_th where wj_id="+wj_id;
               st.executeQuery(sql);
               //对档号配置表进行操作,根据配置生成档号
               sql="select count(*) as count1  from pz_archiveno where archiveno__moduleflag = 'wd'";
                rs=st.executeQuery(sql);
                rs.next();
                count=rs.getInt("count1");
                if (count!=0){
                  errmessage="对不起,档号没有配置!";
                  return false;
                }
                //利用循环取档号配置信息
                for (int i=0;i<count; i++)
                {
                  sql="select Archiveno_fieldname,Archiveno_fieldlen,Archiveno_fielddivision  as fieldname,fieldlen,fielddivision  from  pz_archiveno  where  archiveno__moduleflag = 'wd' and archiveno_order = " +i;
                  rs=st.executeQuery(sql);
                  rs.next();
                  fieldname=rs.getString("fieldname");
                  fieldlen =rs.getInt("fieldlen");
                  fielddivision=rs.getString("fielddivision");
                  //取得表中字段的类型
                     
                  sql="select * from da_wj_th ";
                  rs=st.executeQuery(sql);
                  java.sql.ResultSetMetaData rm = rs.getMetaData();
                  int columNumber = rm.getColumnCount();
                  for(int ii = 1; ii <= columNumber; ii ++){
                    String name = rm.getColumnName(i);
                    String type = rm.getColumnTypeName(i);
                    //根据类型,用不同的方法取表中的数据值
                    if (type=="char")
                    {  
                     if (name==fieldname)
                     {
                     sql="select "+fieldname+"  as fieldvalue  from da_wj_th where wj_id="+wj_id;
                     rs=st.executeQuery(sql);
                     rs.next();
                     fieldvalue=rs.getString("fieldvalue");
                     }
                    }
                    else
                    {
                     sql="select to_char("+fieldname+",'yyyy') as fieldvalue from da_wj_th  where wj_id="+wj_id;
                            rs=st.executeQuery(sql);
                     rs.next();
                     fieldvalue=rs.getString("fieldvalue");
                    }
                    
                   
                       
                    
                    }
                  
                  wj_dh=wj_dh+fieldvalue+fielddivision;            }
                sql="update da_wj_sc  set Wj_archiveno='"+wj_dh+ "' where wj_id ="+wj_id;
                st.executeUpdate(sql);
    }
    catch (Exception e){
    throw new Exception(e.getMessage());
    }finally
    {
    disConnect();
     return true;
    }
    }
    }有点长,谢谢了!!!
      

  2.   

    字符串的索引,什么意思,我的代码在上面,能详细告知吗???
      

  3.   

    建议你在代码的形象性方面多加点功夫