在android中使用ormlite执行查询时出现问题
我正在使用 此编程博客用于使用预填充的 sqlite 表。我试图在表中插入任何行,但它总是给出 SQLException:
Problems executing Android query: SELECT * FROM `user` WHERE `username`='Shadow'
这是我收到此错误的方法:
public User getByUsername(String username) {
try {
QueryBuilder<User, String> qb = userDao.queryBuilder();
qb.where().eq("username", username);
PreparedQuery<User> pq = qb.prepare();
return userDao.queryForFirst(pq);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
寻求帮助...
I'm using the program found on this programming blog for using pre-populated sqlite table. I am trying to insert any row in the table but it is giving always SQLException:
Problems executing Android query: SELECT * FROM `user` WHERE `username`='Shadow'
This is the method where I'm getting this error:
public User getByUsername(String username) {
try {
QueryBuilder<User, String> qb = userDao.queryBuilder();
qb.where().eq("username", username);
PreparedQuery<User> pq = qb.prepare();
return userDao.queryForFirst(pq);
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
Looking for help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有有关您收到的特定错误的更多信息(请在您的问题中添加完整的异常),我们无法真正帮助您@deepak,
我会说您的代码看起来格式良好且合适。我喜欢定义在查询中使用的字段,如下所示:
然后您的代码可以如下所示。这解决了查询和数据库模式不匹配的问题:
如果您发布异常,我将在更多帮助下编辑我的答案。
Without more information about the specific error you are getting (please add the full exception to your question), we can't really help you @deepak
I will say that your code looks well formed and appropriate. I like to define the fields that I use in queries like the following:
Then your code can be something like the following. This solves problems with queries and database schemas not matching:
If you post your exception, I'll edit my answer with more help.
不要忘记编写实体类的默认构造函数。就我而言,我忘记编写构造函数并得到相同的异常。
Dont forget to write the default constructor of your Entity Class. In my case i forgot to write the constructor and was getting the same exception.