Java.sql.SQLException: unable to start stmt insert on object

I am trying to insert a record into a database, but it does not work on Android, although I did it before. This is the first time I work with multiple tables in ORMLite.

This is what I am trying to do: Storing data from XML into a model Then try to insert 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 canโ€™t understand where I was wrong. Someone please help !!!

Here is the stack trace (Log Cat received):

 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) 
+4
source share
2 answers

It seems to me that you are not creating a table for tbdriverinfobo .

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

Can you show your onCreate() method in helper? Does your application have an existing database, and you added this table later? Need to increase your database version number?

+11
source

You get this error because you created your database and tables in front of the new table you want

tbDriverInfoBO (this is your new table)

and the ORMLite library throws an exception, for example, โ€œCould not find the tbDriverInfoBO table ....โ€, something like this .. So you need to remove your mobile application from your phone, and then you have to write the whole table class for the onCreate method, for example , below code ...

 @Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { TableUtils.createTable(connectionSource, Table1.class); TableUtils.createTable(connectionSource, Table2.class); TableUtils.createTable(connectionSource, Table3.class); TableUtils.createTable(connectionSource, Table4.class); TableUtils.createTable(connectionSource, Table5.class);//you must add all your table class TableUtils.createTable(connectionSource, TableN.class); } catch (SQLException e) { e.printStackTrace(); } } 

after adding the whole table class, you can add data to your local tables ...

I hope my answer helps someone ... happy coding

0
source

All Articles