1

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...

1
  • Can you please post the entire exception? Commented Aug 19, 2011 at 14:24

2 Answers 2

5

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:

@DatabaseTable(tableName = "users")
public class User @{
    public static final String USERNAME_FIELD_NAME = "username"; 

    ...
    @DatabaseField(columnName = USERNAME_FIELD_NAME)
    private String userName;
    ...

Then your code can be something like the following. This solves problems with queries and database schemas not matching:

qb.where().eq(User.USERNAME_FIELD_NAME, username);    

If you post your exception, I'll edit my answer with more help.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your response,But this is also occuring when i'm executing the daoObject.queryForAll() method and it is giving the same SQLEXCEPTION Problems executing Android query: SELECT * FROM user .
Can you please post the entire exception to your question?
I debug my source code and i found that query method of StatementExecuter class is throwing SQL Exception but i'm not gettind what is the reason behind it.
Thanks dude with your approach i debug again and found that the error was due to wrong column name.Any way your idea for posting entire exception give a clue to me and i attached the source code of the ormlite and found the solution thanks once again
0

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.

public User(){

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.