Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 不从搜索查询中检索任何数据_Database_Search_Jpa_Derby - Fatal编程技术网

Database 不从搜索查询中检索任何数据

Database 不从搜索查询中检索任何数据,database,search,jpa,derby,Database,Search,Jpa,Derby,我需要搜索所有用户名,并让应用程序打印出包含搜索字符串的所有用户名。我想我已经这样做了,但是当我执行searchByString()时,我没有得到任何结果 抽象立面 /* trying out a search function */ public List<T> searchByString(String string) { System.out.println("in SearchByString"); return getEntityManager().crea

我需要搜索所有用户名,并让应用程序打印出包含搜索字符串的所有用户名。我想我已经这样做了,但是当我执行
searchByString()
时,我没有得到任何结果

抽象立面

/* trying out a search function */
public List<T> searchByString(String string) {
    System.out.println("in SearchByString");
    return getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("username", "%" + string + "%").getResultList();
}

我找不到一张填好的名单。我想知道查询是否正确运行并检索任何内容,因此我希望能够看到它在运行时检索到的内容,以便了解为什么没有向用户显示任何内容。

您的查询参数看起来像是需要一个like子句,但您的命名查询使用=。改变

SELECT u FROM Userdetails u WHERE u.username = :username


而且应该可以用。

非常感谢,现在一切都可以用了!几天来我一直被困在这个问题上,所以谢谢你!!!!
SELECT u FROM Userdetails u WHERE u.username = :username
SELECT u FROM Userdetails u WHERE u.username like :username