日期:2014-05-19  浏览次数:20837 次

求大神指教,这是什么原因,,小弟实在查不出是什么错了
public ArrayList<New> selectnew(int cate,String title){
ArrayList<New> newlist= new ArrayList<New>();
String sql="select * from TB.NEWS_DETAIL where category=? and title like '%?%'";
try {
conn= this.getConn();
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1, cate);
pstmt.setString(2, title);
rs=pstmt.executeQuery();
while(rs.next()){
New news= new New();
news.setId(rs.getString("id"));
news.setCategory(rs.getInt("category"));
news.setTitle(rs.getString("title"));
news.setSummary(rs.getString("summary"));
news.setAuthor(rs.getString("author"));
news.setCreatedate(rs.getString("createdate"));
newlist.add(news);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newlist;
}

java.sql.SQLException: ORA-01006: 绑定变量不存在
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:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527)
at dao.NewDao.selectnew(NewDao.java:41)
at dao.NewDao.main(NewDao.java:60)
[]

------解决方案--------------------
'%?%'
你都已经把它做成字符串了,数据库就不认为它是一个变量了。


语句应该是:
and title like ?
设值:
pstmt.setString(2, "%"+title+"%");