MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 求字符串的部分内容从数据库替换的有关问题(人)

求字符串的部分内容从数据库替换的有关问题(人)

www.MyException.Cn  网友分享于:2013-12-05  浏览:290次
求字符串的部分内容从数据库替换的问题(人在线等)
我数据库里保存的是这串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="\"+mb_sqlstr+"\";
  out.print(mb_sqlstr+"<BR>");
  sum++;
}
ds2.close();
//ds3.close();
out.print("<BR>本次一共更新:"+sum+"条记录。");
%>

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有