Oracle模糊查询怎么给?传值,下面的代码java.sql.SQLException: 无效的列索引,谢谢

//模糊查询
public void selbylike(String x){
Connection conn = null;
conn= cf.getconn();
PreparedStatement prep = null;
ResultSet rs = null;
String sql = "select * from emp where ename like '%'+?+'%'";
try {
prep = conn.prepareStatement(sql);
prep.setString(0, x);
rs = prep.executeQuery();
while(rs.next()){
System.out.println(rs.getInt("empno")+" "+rs.getString("ename") + " "+rs.getString(3)+ " "+rs.getString(4)+ " "+rs.getString(5)+ " "+rs.getString(6)+ " "+rs.getString(7)+ " "+rs.getString(8));
}
} catch (SQLException e) {
e.printStackTrace();
}

}
不是这 String sql = "select * from emp where ename like '%'+?+'哗知%'";
String sql = "select * from emp where ename like '%?%'";
就是这System.out.println(rs.getInt("empno")+" "+rs.getString("ename") + " "+rs.getString(3)+ " "+rs.getString(4)+ " "+rs.getString(5)+ " "+rs.getString(6)+ " "+rs.getString(7)+ " "+rs.getString(8));

错了,你看看emp是不是有empno和ename的属性,再看看第3,4,5,6,7,8个属乱庆消性是否有值,并且差缺是不是String类型的
oracle字符串相加是||不是+
String sql = "select * from emp where ename like '%"+?+"%'";
不是颂猛橡单引号多了,而是双引号少知旅了,你原来的相当于是直接like %'?'野旁% 这么一个字符串了,而不是like '%?%'
select * from emp where ename like '%+?+%'
多了两个单引号