日期:2014-05-18  浏览次数:20710 次

求字符串的部分内容从数据库替换的问题(人在线等)
我数据库里保存的是这串sql
insert into blob_fjsc(blob_wid,blob_mkmc,blob_data,blob_scsj,blob_fjmc,blob_scr) values('"+ds2.getString("blob_wid")+"','"+ds2.getString("blob_mkmc")+"','','"+ds2.getString("blob_scsj")+"','"+ds2.getString("blob_fjmc")+"','"+ds2.getString("blob_scr")+"')
具体思路是这样的,我写一段sql,但是这段的取值我已经从页面中写好了,就是ds2.getString()取到,目前是我想另外一个ds的数据库操作来运行这串sql,添加进去数据库的则是"+ds2.getString("blob_mkmc")+"这么一串东西,而不是我想要的值,我如何能将这串中的ds部分换取所需要的具体值?这串拷贝进去是不会出错的,但是当作变量进去就会报错,代码如下。
Java code

<%
String id=request.getParameter("id");
String sqlstr1,sqlstr2,sqlstr3;
String sm="",ms="",sqlselect_str="",ysjkpz="",mb_sqlstr="",mbsjkpz="",gxsz="",n_indexfield="",o_indexfield="";
int dssz,xhcs,dbconfig,indexconfig;
//更新的条件获取
sqlstr1="select * from sjjh_config where sjjh_config_id="+id;
ds.setCommand(sqlstr1,"oa");
ds.execute();
if(ds.next()){
  sm=ds.getString("sm");
  ms=ds.getString("ms");
  sqlselect_str=ds.getString("sqlselect_str");
  ysjkpz=ds.getString("ysjkpz");
  mb_sqlstr=ds.getString("mb_sqlstr");
  mbsjkpz=ds.getString("mbsjkpz");
  gxsz=ds.getString("gxsz");
  o_indexfield=ds.getString("o_indexfield");
  n_indexfield=ds.getString("n_indexfield");
  
  dssz=ds.getInt("dssz");
  xhcs=ds.getInt("xhcs");
  dbconfig=ds.getInt("dbconfig");
  indexconfig=ds.getInt("indexconfig");
}
ds.close();
//获取插入字段名
/**String str = mb_sqlstr;
        String ss = str.substring(str.indexOf("$") - 1,
            str.lastIndexOf("$") + 2);
        String[] arys = ss.split("\\,");
        
        List<String> list = new ArrayList<String>();
        
        for (int i = 0; i < arys.length; i++)
        {
            String temp = arys[i];
            
            String date = temp.substring(temp.indexOf("$") + 1,
                temp.lastIndexOf("$"));
            
            list.add(date);
            
            
        }
        System.out.println(list);
**/
//查找目标数据源

ds2.setCommand(sqlselect_str,ysjkpz);
ds2.execute();
int sum=0;
while(ds2.next()){

  //mb_sqlstr = mb_sqlstr.replaceAll("\'\\$", "\'\"\\+");
  //mb_sqlstr = mb_sqlstr.replaceAll("\\$\'", "\\+\"\'");
  mb_sqlstr= "insert into blob_fjsc(blob_wid,blob_mkmc,blob_data,blob_scsj,blob_fjmc,blob_scr) values("+ds2.getString("blob_wid")+","+ds2.getString("blob_mkmc")+",'',"+ds2.getString("blob_scsj")+","+ds2.getString("blob_fjmc")+","+ds2.getString("blob_scr")+")";
   //mb_sqlstr="\""+mb_sqlstr+"\"";
   //mb_sqlstr="insert into blob_fjsc(blob_wid,blob_mkmc,blob_data,blob_scsj,blob_fjmc,blob_scr) values('"+ds2.getString("blob_wid")+"','"+ds2.getString("blob_mkmc")+"','','"+ds2.getString("blob_scsj")+"','"+ds2.getString("blob_fjmc")+"','"+ds2.getString("blob_scr")+"')";
  //ds3.executeUpdate(mb_sqlstr,mbsjkpz);
  //ds3.executeUpdate("insert into blob_fjsc(blob_wid,blob_mkmc,blob_data,blob_scsj,blob_fjmc,blob_scr) values('"+ds2.getString("blob_wid")+"','"+ds2.getString("blob_mkmc")+"','','"+ds2.getString("blob_scsj")+"','"+ds2.getString("blob_fjmc")+"','"+ds2.getString("blob_scr")+"')",mbsjkpz);
  mb_sqlstr