如何更新我的字符串值转换成数据库 [英] How to update my string value into database
问题描述
与表名称状态
和列名称的数据库是列1
。我需要更新此。
我在活动1
字符串检查=值;
我已经过了这个值进入我的 DBHelper
。我已经试过这样
dbhelper =新DBHelper(本);
dbhelper.sample(检查);
我在 DBHelpe
r.here此值。像这样
公共无效样本(字符串PRMS){
Log.d(sucess,PRMS);
}
现在我怎么需要更新字符串PRMS
到我的数据库的ColumnName 列1
我已经试过这样
公共无效样本(字符串PRMS){
Log.d(DBHELPER成功,PRMS);
尝试{
SQLiteDatabase DB1 = this.getWritableDatabase();
db1.execSQL(更新appstatus设置状态='+ PRMS +'WHERE ID = 1);
}赶上(例外五){
的System.out.println(GET采样值+ E);
}
}
有什么毛病我的语法?如何实现这一目标?
它显示异常,如
12月2日至28号:09:45.604:我/的System.out(4975):GET样品VALUEandroid.database.sqlite.SQLiteException:表报告已经存在(code 1 ):在编制:创建表报告(级文本,主题文本,文本开始,结束文字,日期文字)
rawQuery()
不实际运行的SQL。使用 execSQL()
来代替:
db.execSQL(更新状态设置列1 ='+ PRMS +');
(见<一href="http://stackoverflow.com/questions/20110274/what-is-the-correct-way-to-do-inserts-updates-deletes-in-android-sqlitedatabase/20118910#20118910">What是做插入/更新/使用查询字符串的Android SQLiteDatabase删除?了解详情如何 rawQuery()
和的正确方法execSQL()
引擎盖下工作。)
Have a database with table name status
and column name is column1
. I need to update this.
I have a String value in Activity1
String check = "value";
I have passed this value into my DBHelper
.I have tried like this
dbhelper = new DBHelper(this);
dbhelper.sample(check);
I got this value in DBHelpe
r.here. Like this
public void sample(String prms){
Log.d("sucess",prms);
}
Now how i need to update String prms
into my database columnname column1
I have tried like this
public void sample( String prms) {
Log.d("DBHELPER SUCCESS", prms);
try{
SQLiteDatabase db1 = this.getWritableDatabase();
db1.execSQL("update appstatus SET status = '"+prms+"' WHERE id = 1 ");
}catch(Exception e){
System.out.println("GET SAMPLE VALUE"+e);
}
}
What's wrong with my syntax? How to achieve this?
It shows exception as
02-28 12:09:45.604: I/System.out(4975): GET SAMPLE VALUEandroid.database.sqlite.SQLiteException: table report already exists (code 1): , while compiling: create table report(level TEXT, topic TEXT, start TEXT, end TEXT, date TEXT)
rawQuery()
doesn't actually run the SQL. Use execSQL()
instead:
db.execSQL("update status SET column1 = '"+prms+"' ");
(See What is the correct way to do inserts/updates/deletes in Android SQLiteDatabase using a query string? to learn more how rawQuery()
and execSQL()
work under the hood.)
这篇关于如何更新我的字符串值转换成数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!