有JDBC编程的人都会知道这是一个什么样的异常。做为刚出道的菜鸟我可因为这个异常把我整一下。
我希望这小段随笔能给阅读都带来帮助,也希望大家多多指教。
我在EJB中写了一个方法:public Vector searchCase(String dataSource,BlacksmokeEnqDataobject inputObj,String sql,int maxAllowSize){
Connection con = null;
Vector VqueryData = null;
PreparedStatement ps = null;
ResultSet rs = null;
FormatFunctions ff = new FormatFunctions();
BlacksmokeEnqReportDataobject blsObj = null;
SqlFunctions sf = new SqlFunctions();
try{
con = getConnection(dataSource);
String drv_ic_n = inputObj.getDrv_ic_n();
String caseType = inputObj.getCaseType();
String vehicleNo = inputObj.getVehNo();
String fleetType = inputObj.getFleetType();
String make = inputObj.getMake();
String model = inputObj.getModel();
String payFrom = inputObj.getPayDateFrom();
String payTo = inputObj.getPayDateTo();
String offFrom = inputObj.getOffeDateFrom();
String offTo = inputObj.getOffeDateTo();
String entryFrom = inputObj.getEntryDateFrom();
String entryTo = inputObj.getEntryDateTo();
int smokeFrom = inputObj.getSmokeFrom();
int smokeTo = inputObj.getSmokeTo();
if (drv_ic_n.equals("")){
drv_ic_n = null;
}
if (caseType.equals("")){
caseType = null;
}
if (vehicleNo.equals("")){
vehicleNo = null;
}
if (fleetType.equals("")){
fleetType = null;
}
if (make.equals("")){
make = null;
}
if (model.equals("")){
model = null;
}
if (payFrom.length()>0 && payFrom.equalsIgnoreCase("00/00/0000")){
payFrom = null;
}
if (payTo.length()>0 && payTo.equalsIgnoreCase("00/00/0000")){
payTo = null;
}
if (offFrom.length()>0 && offFrom.equalsIgnoreCase("00/00/0000")){
offFrom = null;
}
if (offTo.length()>0 && offTo.equalsIgnoreCase("00/00/0000")){
offTo = null;
}
if (entryFrom.length()>0 && entryFrom.equalsIgnoreCase("00/00/0000")){
entryFrom = null;
}
if (entryTo.length()>0 && entryTo.equalsIgnoreCase("00/00/0000")){
entryTo = null;
}
String tmpSql = sf.retuSqlS(sql);
tmpSql = sf.linkSql(tmpSql,":LS_CO_FINE_PAID_D_FROM",payFrom);
tmpSql = sf.linkSql(tmpSql,":LS_CO_FINE_PAID_D_TO",payTo);
tmpSql = sf.linkSql(tmpSql,":LS_BLS_OFFENCE_D_FROM",offFrom);
tmpSql = sf.linkSql(tmpSql,":LS_BLS_OFFENCE_D_TO",offTo);
tmpSql = sf.linkSql(tmpSql,":LS_ENTRY_D_FROM",entryFrom);
tmpSql = sf.linkSql(tmpSql,":LS_ENTRY_D_TO",entryTo);
ps = con.prepareStatement(tmpSql);
// System.out.println(tmpSql);
int idx = 0;
ps.setString(++idx,drv_ic_n);
ps.setString(++idx,drv_ic_n);
ps.setString(++idx,caseType);
ps.setString(++idx,caseType);
ps.setString(++idx,vehicleNo);
ps.setString(++idx,vehicleNo);
ps.setString(++idx,fleetType);
ps.setString(++idx,fleetType);
ps.setString(++idx,make);
ps.setString(++idx,make);
ps.setString(++idx,model);
ps.setString(++idx,model);
ps.setInt(++idx,smokeFrom);
ps.setInt(++idx,smokeFrom);
ps.setInt(++idx,smokeTo);
// ps.setInt(++idx,smokeTo);
ps.executeQuery();
rs = ps.getResultSet();
VqueryData = new Vector();
idx = 0;
while(rs.next() && idx <= maxAllowSize){
blsObj = new BlacksmokeEnqReportDataobject();
blsObj.setDRV_IC_N(rs.getString("DRV_IC_N"));
blsObj.setDRV_NM(rs.getString("DRV_NM"));
blsObj.setBLS_CASE_N(rs.getString("BLS_CASE_N"));
blsObj.setBLS_CASE_T(rs.getString("BLS_CASE_T"));
blsObj.setVEH_REGN_N(rs.getString("VEH_REGN_N"));
blsObj.setBLS_FLT_T(rs.getString("BLS_FLT_T"));
blsObj.setBLS_MAKE_C(rs.getString("BLS_MAKE_C"));
blsObj.setBLS_MODEL_C(rs.getString("BLS_MODEL_C"));
blsObj.setBLS_OFFENCE_D(ff.dateFormat(rs.getDate("BLS_OFFENCE_D")));
blsObj.setENTRY_D(ff.dateFormat(rs.getDate("ENTRY_D")));
blsObj.setSMOKE_LEV_READ(rs.getInt("SMOKE_LEV_READ"));
blsObj.setCO_FINE_PAID_D(ff.dateFormat(rs.getDate("CO_FINE_PAID_D")));
VqueryData.addElement(blsObj);
idx++;
}
}catch(Exception e){
blsObj.setErrStatus(sf.ckException(e));
VqueryData.addElement(blsObj);
e.printStackTrace();
}finally{
SqlFunctions.cleanup(ps, rs);
SqlFunctions.cleanup(con);
}
return VqueryData;
}这是一个通过XML文件来传SQL语。把查询语句写在XML文件中,在Servlet中调用XML文件。
上面那个错误是因为没有对XML中的查询变量进行绑定,或者是多写,或少写变量,或者变量名写错了。后来我重新认真的做了一遍,发生我没有写错。我把JDeveloper关了,重新打开,可以了。我的没有想这是怎么一回,如果有同样问题的好友知道这是怎么一回事,请联系我
rodney_luo@163.com. QQ:86322591