当前位置: 技术问答>java相关
送分了151分,只要帮我解决这个问题;
来源: 互联网 发布时间:2015-07-21
本文导语: import ToStr; import OpenDb; import java.sql.*; import javax.servlet.http.*; public class SaveDb { public int SetSave(HttpServletRequest request,String formstr,String tblname){ try{ String t_tmps; int rc=0; St...
import ToStr;
import OpenDb;
import java.sql.*;
import javax.servlet.http.*;
public class SaveDb
{
public int SetSave(HttpServletRequest request,String formstr,String tblname){
try{
String t_tmps;
int rc=0;
String strField="";
String strValue="";
String t_name,t_type;
int i,pos;
ToStr ts=new ToStr();
String fmt=formstr;
rc=0;
while(fmt.indexOf(",")!= -1){
pos=fmt.indexOf(",");
if(pos==0)break;
t_tmps=fmt.substring(0,pos);
i=t_tmps.indexOf("|");
if(i>=0)t_name=t_tmps.substring(0,i);
else t_name=t_tmps;
i=t_tmps.indexOf("C:");
if(i>=0){
t_type=t_tmps.substring(i+2,i+3);
}
else t_type="C";
t_tmps=ts.getStr(request.getParameter(t_name));
if(t_tmps!=null&&t_tmps.length()!=0){
strField+=","+t_name;
if(t_type.compareTo("C")==0){
strValue+=",'"+t_tmps+"'";
rc=1;
}
if(t_type.compareTo("D")==0){
strValue+=",'"+t_tmps+"'";
rc=1;
}
if(t_type.compareTo("F")==0){
strValue+=","+Double.parseDouble(t_tmps);
rc=1;
}
if(t_type.compareTo("L")==0){
strValue+=","+Integer.parseInt(t_tmps);
rc=1;
}
}
fmt=fmt.substring(pos+1);
}
if(rc!=0){
String strSQL="INSERT INTO "+tblname+"("+strField+") Values("+strValue+")";
OpenDb od=new OpenDb();
rc=od.executeUpdate(strSQL);
return rc;
}
else return -1;
}
catch(Exception ex){
System.err.println("sq.executeUpdate:"+ex.getMessage());
return -1;
}
}
}
import OpenDb;
import java.sql.*;
import javax.servlet.http.*;
public class SaveDb
{
public int SetSave(HttpServletRequest request,String formstr,String tblname){
try{
String t_tmps;
int rc=0;
String strField="";
String strValue="";
String t_name,t_type;
int i,pos;
ToStr ts=new ToStr();
String fmt=formstr;
rc=0;
while(fmt.indexOf(",")!= -1){
pos=fmt.indexOf(",");
if(pos==0)break;
t_tmps=fmt.substring(0,pos);
i=t_tmps.indexOf("|");
if(i>=0)t_name=t_tmps.substring(0,i);
else t_name=t_tmps;
i=t_tmps.indexOf("C:");
if(i>=0){
t_type=t_tmps.substring(i+2,i+3);
}
else t_type="C";
t_tmps=ts.getStr(request.getParameter(t_name));
if(t_tmps!=null&&t_tmps.length()!=0){
strField+=","+t_name;
if(t_type.compareTo("C")==0){
strValue+=",'"+t_tmps+"'";
rc=1;
}
if(t_type.compareTo("D")==0){
strValue+=",'"+t_tmps+"'";
rc=1;
}
if(t_type.compareTo("F")==0){
strValue+=","+Double.parseDouble(t_tmps);
rc=1;
}
if(t_type.compareTo("L")==0){
strValue+=","+Integer.parseInt(t_tmps);
rc=1;
}
}
fmt=fmt.substring(pos+1);
}
if(rc!=0){
String strSQL="INSERT INTO "+tblname+"("+strField+") Values("+strValue+")";
OpenDb od=new OpenDb();
rc=od.executeUpdate(strSQL);
return rc;
}
else return -1;
}
catch(Exception ex){
System.err.println("sq.executeUpdate:"+ex.getMessage());
return -1;
}
}
}
|
这回不用担心了吧,还好今天工作努力,呵呵,刚装上了wsad,不然还没办法搞定
关键就是那段字符转换的代码,看得头都晕了,不过还好我的调试器比较好,把错误信息都显示出来了,最后发现
那段代码得到的strValue和trField前面都多了一个分号
关键就是那段字符转换的代码,看得头都晕了,不过还好我的调试器比较好,把错误信息都显示出来了,最后发现
那段代码得到的strValue和trField前面都多了一个分号