RepositoryException:org.sql2o.Sql2oException:数据库错误:查询未返回任何结果

时间:2019-01-23 08:05:20

标签: java postgresql sql2o

我将Postgres sql用作数据库,将java用作后端。我正在将sql2o与Java代码一起使用,如下所示。

public Category insertCategory(Category category) {
        // TODO Auto-generated method stub
        System.out.println(category.getName());
        String query = getQuery("insertCategory");
        try (Connection conn = getConnection()) {
        conn.createQuery(query).bind(category).executeAndFetchFirst(Category.class);

            return null;
        }
        catch(Throwable t) {
            throw new RepositoryException(t);
        }
    }

类别类是一个模型,其中包含名称,描述,标题之类的属性。

public class Category extends Entity {
    private long id;
    private String name;
    private String description;
    private String title;
}

查询:

insert into category(name, description, title, icon) values(:name, :description, :title, :icon) returning * 

我正在使用返回*来获取插入的记录,如上所示。但是我遇到了以下错误

com.hiya.repo.utils.RepositoryException: org.sql2o.Sql2oException: Database error: No results were returned by the query.
    at com.hiya.repo.orientdb.CategoryServiceImpl.insertCategory(CategoryServiceImpl.java:70)
    at com.hiya.repo.orientdb.TestCategoryServiceImpl.testInsertCategory(TestCategoryServiceImpl.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 

我在某个地方出问题了吗?

0 个答案:

没有答案