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)
……………………
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)
……………………
解决方案 »
- MAP里放LIST集合,怎么用JSTL循环输出
- 怎么用application实现网站统计人数,如果用户刷新页面含是同样人数,请高手给一个例子看看。
- java如何读取硬盘上某个文件夹路径,循环出所有目录结合dtree展示在jsp页面
- struts2中多个action间的ActionError传递问题
- 【java2000_net】 进度条图片控制问题???
- jbuilder2005工程的移植问题
- 就是因为这么一个小问题,使我的工作往后推,大家看看值不值得
- 请问jsp的入门问题。
- 一段简单的数据库调用代码!请大虾帮忙看看!!
- jsp怎么实现从邮件服务器接收的邮件不重复
- ServletListener的问题
- 小女子求助各位大侠--关于ireport的问题
select * from Data0024 where 1=1 and supplier_ptr = ? and factory_location = '
大船(广州)电子有限公司'
setBigDecimal(1, 50992)
setString(2, 大船(广州)电子有限公司)
为什么 set两个参数 应该有问题吧
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 + ") ");
}