public boolean findByField(Map p_table, Connection p_conn ) throws SQLException {
        PreparedStatement l_pstmt=null; ResultSet l_rs=null;
        int rtn=0;
        boolean l_return = false;
        Object p_object = null;
        //java.util.Enumeration key_Enum;
        java.util.Iterator keyItor;
        try {
            //get table name:
            String tableName = getTableName();
            tableName = tableName.substring( tableName.lastIndexOf('.')+1 );
            String l_sql = "select * from " + tableName + " where 1=1 " ;
            
            if (p_table.isEmpty()) throw new SQLException ("Empty map.");            
            Object[] listOfObject = new Object[ p_table.size()*2 ];
            keyItor = p_table.keySet().iterator();
            
            int counter=0;
            //This is converted into a list because the ordering of hashtable cannot be trusted.
            //This makes sure the order in the SQL string is correct with the ? index.
            while (keyItor.hasNext()) {
                String key = (String) keyItor.next();
                p_object = p_table.get(key);
                listOfObject[counter++]=key;
                //System.out.println("counter:"+ (counter-1) + listOfObject[counter-1]);
                listOfObject[counter++]=p_object;
                //System.out.println("counter:"+ (counter-1) + listOfObject[counter-1]);
                
                if (p_object==null || ((p_object instanceof String)&&p_object.equals("")) ) {
                    l_sql += " and " + key + " is null ";
                } else if (p_object instanceof String) {
                    l_sql += " and " + key + " = '"+GlobalSQLFunctions.encodeSQL((String)p_object)+"' ";
                } 
                else {
                    l_sql += " and " + key + " = ? ";
                }
            }
            System.out.println( l_sql );
            int minusStringIndex=0;
            l_pstmt = p_conn.prepareStatement(l_sql);
            
            for (counter=1; counter<p_table.size()*2; counter+=2) {
                p_object = listOfObject[counter];
                if (p_object==null || p_object instanceof String) {
                    //l_pstmt.setString((counter+1)/2, (String) p_object );
                    System.out.println("setString(" + (counter+1)/2 + ", " + p_object + ") ");
                    minusStringIndex++; //make sure the parameter index is set correctly.
                } else if (p_object instanceof java.math.BigDecimal) {
                    l_pstmt.setBigDecimal( ((counter+1)/2)-minusStringIndex, (java.math.BigDecimal) p_object );
                    System.out.println("setBigDecimal(" + (counter+1)/2 + ", " + p_object + ") ");
                } else if (p_object instanceof java.util.Date) {
                    GlobalSQLFunctions.setUtilDate( l_pstmt, ((counter+1)/2)-minusStringIndex, (java.util.Date) p_object );
                    System.out.println("setUtilDate(" + (counter+1)/2 + ", " + p_object + ") ");
                } else if (p_object instanceof java.sql.Date) {
                    GlobalSQLFunctions.setUtilDatetime( l_pstmt, ((counter+1)/2)-minusStringIndex, (java.util.Date) p_object );
                    System.out.println("setUtilDatetime(" + (counter+1)/2 + ", " + p_object + ") ");
                } else {
                    l_pstmt.setObject( ((counter+1)/2)-minusStringIndex , p_object );
                    System.out.println("setObject(" + (counter+1)/2 + ", " + p_object + ") ");
                }
            }            l_rs = l_pstmt.executeQuery();System.out.println("111");
            if (l_rs.next()) {
                l_return = true;     System.out.println("222");           
                GlobalSQLFunctions.resultSet2Bean(l_rs, 0, this );System.out.println("333");
            }
            System.out.println("find or not "+l_return);
        } catch (SQLException sqle) {
            System.out.println( "findByField(Map,Conn): " + sqle.getMessage() );
            sqle.printStackTrace();
            throw sqle;
        } finally {
            if (l_rs!=null) try {l_rs.close();} catch (Exception ignore) {}
            if (l_pstmt!=null) try {l_pstmt.close();} catch (Exception ignore) {}
        }
        return l_return;
    } //end of findByField后台打印内容如下 
select * from Data0024 where 1=1  and supplier_ptr = ?  and factory_location = '
大船(广州)电子有限公司'
setBigDecimal(1, 50992)
setString(2, 大船(广州)电子有限公司)
findByField(Map,Conn): ORA-00933: SQL command not properly endedjava.sql.SQLException: ORA-00933: SQL command not properly ended        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
        at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
        at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:
880)
……………………

解决方案 »

  1.   

    sql命令可能没有结束、把你后台完整sql语句输出来看下是什么样的。
      

  2.   

    己经打印了啊 
    select * from Data0024 where 1=1 and supplier_ptr = ? and factory_location = '
    大船(广州)电子有限公司'
      

  3.   

    select * from Data0024 where 1=1 and supplier_ptr = ? and factory_location = '
    setBigDecimal(1, 50992)
    setString(2, 大船(广州)电子有限公司)
    为什么 set两个参数 应该有问题吧
      

  4.   

    没有问题,上面有段代码有贴:
    if (p_object==null || p_object instanceof String) {
      //l_pstmt.setString((counter+1)/2, (String) p_object );
    这个地方给注释掉了,仅打印数据
      System.out.println("setString(" + (counter+1)/2 + ", " + p_object + ") ");
      minusStringIndex++; //make sure the parameter index is set correctly.
      } else if (p_object instanceof java.math.BigDecimal) {
      l_pstmt.setBigDecimal( ((counter+1)/2)-minusStringIndex, (java.math.BigDecimal) p_object );
      System.out.println("setBigDecimal(" + (counter+1)/2 + ", " + p_object + ") ");
      }