遍历emp表,通过enamel打印出empno,系统提示错误,求帮助
public class UseDb {
public List<Seach> queryByEName(String eName){
List<Seach> seachs = new ArrayList<Seach>();
Seach seach=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott",
"tiger");
String sql = "SELECT * FROM EMP WHERE ENAME LIKE '?%?'";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, eName);
ResultSet rs = pstmt.executeQuery();
for(;;){
if(rs.next()) break;
seach = new Seach();
seach.setEmpNo(rs.getInt("empNo"));
seachs.add(seach);
//System.out.println("测试…………………………………………………………………………………………………………………………………………………………………………"+rs.getInt("empNo"));
}
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (
ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return seachs;
}
}
错误提示:
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)
------解决方案--------------------
SELECT * FROM EMP WHERE ENAME LIKE '%?%'
------解决方案--------------------
String sql = "SELECT * FROM EMP WHERE ENAME LIKE ?%?";