我想将一个表单的值插入到数据库中,其中有两个整数和一个字符串,但我无法在我的SQLite数据库查看器中看到我输入的值。我使用以下代码:
请帮忙...
SQLiteDatabase myDB= null;
String TableName = "basicdetai";
try{
myDB = this.openOrCreateDatabase("Medical", MODE_PRIVATE, null);
/* Create a Table in the Database. */
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ TableName
+ " (order_id INT(4), doc_id INT(4),doc_name VARCHAR );");
/* Insert data to a Table*/
myDB.execSQL("INSERT INTO "
+ TableName
+ "(order_id,doc_id,doc_name)"
+ " VALUES ("+ ordid + ","+ doci + ","+ docnam +");");
// line 10 + " VALUES ("+ a + ","+ b + ","+ docnam +");");
// line 11 +"VALUES (5011,4011,'gupta');");
}
catch(Exception e) {
Log.e("Error", "Error", e);
}
finally {
if (myDB != null)
myDB.close();
}
但是当我在上面的代码中使用第11行时,我可以通过SQLite浏览器看到记录(5011,4011,'gupta')
。
我正在执行以下操作将从表单获取的字符串值转换为整数。
try {
ordid = Integer.parseInt(orderid.getText().toString());
doci = Integer.parseInt(docid.getText().toString());
// qn = Integer.parseInt(qty.getText().toString());
} catch(NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
请帮忙...