Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.SQLException: Unable to run insert stmt on object

I have been trying to insert a record into the database but its not working in Android even though I have done it before. This is the first time I am working with multiple tables in ORMLite.

This is what I am trying to do: Storing data from XML into a model Then trying to insert the data from the model.

DataBase used: SQLite ORM: ORMLite

ActivityClass

TbDriverInfoBO tbDriverInfoBO = new TbDriverInfoBO();
Document doc = XMLfunctions.XMLfromString(strResult);
NodeList nodes = doc.getElementsByTagName("root");
Element root = (Element) nodes.item(0);
jabongModel.setLoginId(XMLfunctions.getValue(root, "UserId"));
jabongModel.setPassword(XMLfunctions.getValue(root, "UserPwd"));
jabongModel.setDrsno(XMLfunctions.getValue(root, "DRSNo"));
jabongModel.setBrancode(XMLfunctions.getValue(root, "BranchCode"));
jabongModel.setLoginDate(XMLfunctions.getValue(root, "LoginDate"));
//clsDriverInfo obj = new clsDriverInfo(loginId, pswd, drsno,
/*tbDriverInfoBO.setColUserId(jabongModel.getLoginId());
tbDriverInfoBO.setColPwd(jabongModel.getPassword());
tbDriverInfoBO.setColDrs(jabongModel.getDrsno());
tbDriverInfoBO.setColBranch(jabongModel.getBrancode());*/

tbDriverInfoBO.fillBo(jabongModel);

dbHelperTbDriverInfo.addData(tbDriverInfoBO);

BOClass:

public class TbDriverInfoBO {

    @DatabaseField(generatedId = true)
    int id;
    @DatabaseField
    String colUserId;
        ...

        // getters and setters

    public TbDriverInfoBO(String colUserId, String colPwd, String colDrs, String colBranch)
    {
        this.colBranch = colBranch;
        this.colDrs = colDrs;
        this.colPwd = colPwd;
        this.colUserId = colUserId;
    }

    public TbDriverInfoBO() {
        // TODO Auto-generated constructor stub
    }
    public void fillBo(JabongModel jabongModel)
    {
       this.colBranch = jabongModel.getBrancode();
       this.colDrs = jabongModel.getDrsno();
       this.colPwd = jabongModel.getPassword();
       this.colUserId = jabongModel.getLoginId();
       //this.id = jabongModel.getId();

    }
}



DBHelperClass
public int addData(TbDriverInfoBO tbDriverInfoBO) {
    int i=0;
    RuntimeExceptionDao<TbDriverInfoBO, String> dao = getTbDriverInfoDaO();
    try{
     i = dao.create(tbDriverInfoBO);
    }
    catch (Exception e) {
        e.getStackTrace();// TODO: handle exception
    }
    return i;
}

I cannot make out where have I gone wrong. Somebody please help!!!

Here is the stack trace(Log Cat Obtained):

01-28 15:43:46.251: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:46.251: D/dalvikvm(368): GC_FOR_MALLOC freed 8148 objects / 498080 bytes in 72ms
01-28 15:43:49.514: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:50.790: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:50.900: I/Database(368): sqlite returned: error code = 1, msg = no such table: tbdriverinfobo
01-28 15:43:58.681: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:44:01.956: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
like image 836
Tejaswi Parande Avatar asked Jan 28 '13 10:01

Tejaswi Parande


1 Answers

Looks to me that you are not creating the table for tbdriverinfobo.

sqlite returned: error code = 1, msg = no such table: tbdriverinfobo

Can you show your onCreate() method in the helper? Does your application have an existing database and you've added this table afterwards? Do you need to increment your database version number?

like image 195
Gray Avatar answered Oct 29 '22 17:10

Gray