public static List getValues(String a)
{

List list = new ArrayList();
String sql = "select * from liuyan where content like '%"+"?"+"%'" ;

try{

ConnFactory cf = new ConnFactory();
conn = cf.getConnection();
ps=conn.prepareStatement(sql);
ps.setString(1, a);
rs = ps.executeQuery();
 LYItem tmp;
while(rs.next())
{
tmp = new LYItem(rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getDate(6));
list.add(tmp);
}
conn.close();
ps.close();
rs.close();
}catch(Exception e)
{
e.printStackTrace();
}

return list;
}java.sql.SQLException: No parameters defined during prepareCall()id   name at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ServerPreparedStatement.getBinding(ServerPreparedStatement.java:751)
at com.mysql.jdbc.ServerPreparedStatement.setString(ServerPreparedStatement.java:1857)
at com.zqxgsj.beans.LYManager.getValues(LYManager.java:54)
at com.zqxgsj.beans.LYManager.main(LYManager.java:126)
提示这个错误,我学的不精,不知道这个到底是哪错误了

解决方案 »

  1.   

    String sql = "select * from liuyan where content like '%'?'%'" ;
      

  2.   

    String sql = "select * from liuyan where content like '%"+a+"%'" ; 
    用 createStatement  Statement
    没不要用预处理。
      

  3.   

    String sql = "select * from liuyan where content like %?%" ; 
    改为这个看看
    或者看看
    rs.getString(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5),rs.getDate(6)这些字段是不是越界了最重要的一点:
    LYItem这个是不是一个bean,
    如果是的话,看有没有
    public LYItem(String a,String b,String c,String e,String f,String h){
    this.a=a;
    this.b=b;
    this.c=c;
    this.e=e;
    this.f=f;
    this.h=h;
    }
      

  4.   

    public LYItem(String a,String b,String c,String e,String f,String h){ 
    this.a=a; 
    this.b=b; 
    this.c=c; 
    this.e=e; 
    this.f=f; 
    this.h=h; 

    在这个构造方法里面,少写了参数!
      

  5.   

    id  name 主要查看这两个参数有没有。
      

  6.   

    现在的主要问题是调用了这个SQL语句之后查询不出来记录。
    但是在MYSQL数据库里面查询就没有问题能出来,所以我想是不是用的PreparedStatement这块有问题。但是我不知道怎么写。
      

  7.   

    换一个跟你mysql版本匹配的驱动试试
      

  8.   

    先看你的数据库能不能连上,如果没有问题,就把你的SQL语句打印出来看看。一般在做模糊查询的时候,出问题都是在你输入了中文,但是打印出来的SQL语句中有乱码,不幸做个断点调试一下。
      

  9.   

    别用问号 
    String sql = "select * from liuyan where content like '%"+"a"+"%'"这样应该就可以了 
      

  10.   

    String sql = "select * from liuyan where content like '%"+a+"%'"  
    试一试吧