安卓:错误使用字符串更新数据库时 [英] Android: Error when updating database using a string

查看:355
本文介绍了安卓:错误使用字符串更新数据库时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库包含演唱会的名单,我根据name列更新它们。当点击更新按钮,给定的演唱会的列值传递。但是,当名称列是单号的更新才起作用。如果名称列是一个字符串,或2 +数字,它立刻崩溃,并给了我以下错误。

  11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:更新艺术家方法:名称=测试值
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:更新艺术家方法:会场值=考场
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:更新艺术家方法:日期值= DD
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:更新艺术家方法:注释值= D
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:DB经理方法:名称值=试验
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:DB经理方法:会场值=考场
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:DB经理法:日期值= DD
11-17 13:14:51.325 12131-12131 / com.example.msdproject I /测试:DB管理方法:注释值= D
11-17 13:14:51.325 12131-12131 / com.example.msdproject E / SQLiteLog:(1)没有这样的列:测试
11-17 13:14:51.335 12131-12131 / com.example.msdproject D / AndroidRuntime:关闭VM
11-17 13:14:51.335 12131-12131 / com.example.msdproject W / dalvikvm:主题ID = 1:螺纹未捕获的异常退出(组= 0x41614ba8)
11-17 13:14:51.355 12131-12131 / com.example.msdproject E / AndroidRuntime:致命异常:主要
    工艺:com.example.msdproject,PID:12131
    android.database.sqlite.SQLiteException:没有这样的列:测试(code 1),在编译:UPDATE Con​​cert_Info设置日期= ?,地点= ?,评论= ?,名=? WHERE NAME =测试
        在android.database.sqlite.SQLiteConnection.native prepareStatement(本机方法)
        在android.database.sqlite.SQLiteConnection.acquire preparedStatement(SQLiteConnection.java:889)
        在android.database.sqlite.SQLiteConnection。prepare(SQLiteConnection.java:500)
        在android.database.sqlite.SQLiteSession。prepare(SQLiteSession.java:588)
        在android.database.sqlite.SQLiteProgram<&初始化GT;(SQLiteProgram.java:58)
        在android.database.sqlite.SQLiteStatement<&初始化GT;(SQLiteStatement.java:31)
        在android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1572)
        在android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1520)
        在com.example.msdproject.DBManager.updateConcert(DBManager.java:150)
        在com.example.msdproject.UpdateArtist.UpdateArtistButton(UpdateArtist.java:103)
        在com.example.msdproject.UpdateArtist $ 1.onClick(UpdateArtist.java:79)
        在android.view.View.performClick(View.java:4438)
        在android.view.View $ PerformClick.run(View.java:18422)
        在android.os.Handler.handleCallback(Handler.java:733)
        在android.os.Handler.dispatchMessage(Handler.java:95)
        在android.os.Looper.loop(Looper.java:136)
        在android.app.ActivityThread.main(ActivityThread.java:5001)
        在java.lang.reflect.Method.invokeNative(本机方法)
        在java.lang.reflect.Method.invoke(Method.java:515)
        在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:785)
        在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        在dalvik.system.NativeStart.main(本机方法)
11-17 13:14:51.365 12131-12131 / com.example.msdproject D / dalvikvm:GC_FOR_ALLOC释放591K,4%免​​费17167K / 17788K,暂停9ms的,9ms的总
11-17 13:14:53.245 12903-12903 / com.example.msdproject I /肾上腺EGL:其中,qeglDrvAPI_eglInitialize:320计算值:1.4 EGL高通公司体形:I0404c4692afb8623f95c43aeb6d5e13ed4b3​​0ddbDate:13年11月6日
11-17 13:14:53.275 12903-12903 / com.example.msdproject D / OpenGLRenderer:启用调试模式0

它是什么,基本上说的是,列不存在,但我不明白为什么它给我这个错误,因为它承认,当我用一个单一的数字列存在。我试图删除_id,但是这给了我同样的结果,所以我恢复到由name列删除。有没有例外,以什么可以传递到数据库更新功能?

下面是updateArtist类:

 包com.example.msdproject;进口android.app.Activity;
进口android.content.Intent;
进口android.database.Cursor;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.Menu;
进口android.view.MenuItem;
进口android.view.View;
进口android.widget.Button;
进口android.widget.EditText;
进口android.widget.TextView;
进口android.widget.Toast;进口值java.sql.SQLException;公共类UpdateArtist延伸活动{    DBManager DB =新DBManager(本);    公众的EditText nameTxt;
    公众的EditText venueTxt;
    公众的EditText dateTxt;
    公众的EditText commentsTxt;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_update_artist);        意向意图= getIntent();
        最终长NUM = intent.getLongExtra(ID,1);        尝试{
            db.open();
            光标C = db.getConcert(NUM);
            如果(c.moveToFirst())
            {
                做
                {
                    字符串名称=(c.getString(1));
                    串场地=(c.getString(2));
                    字符串日期=(c.getString(3));
                    串注释=(c.getString(4));                    TextView的titleTxt =(的TextView)findViewById(R.id.updateTitle);
                    nameTxt =(EditText上)findViewById(R.id.updateName);
                    venueTxt =(EditText上)findViewById(R.id.updateVenue);
                    dateTxt =(EditText上)findViewById(R.id.updateDate);
                    commentsTxt =(EditText上)findViewById(R.id.updateComments);
                    titleTxt.setText(名);
                    nameTxt.setText(名);
                    venueTxt.setText(场地);
                    dateTxt.setText(日期);
                    commentsTxt.setText(评论);                    按钮更新=(按钮)findViewById(R.id.updateConcertButton);
                    update.setOnClickListener(新View.OnClickListener()
                    {
                        @覆盖
                        公共无效的onClick(视图v)
                        {
                            如果(nameTxt.getText()。的toString()的isEmpty()|| venueTxt.getText()。的toString()的isEmpty()||
                                    dateTxt.getText()。的toString()的isEmpty()|| commentsTxt.getText()。的toString()的isEmpty())
                            {
                                Toast.makeText(UpdateArtist.this,Toast.LENGTH_LONG错误请填写在各个领域的!).show();
                            }
                            其他
                            {                                字符串updatedName = nameTxt.getText()的toString()。
                                。字符串updatedVenue = venueTxt.getText()的toString();
                                。字符串updatedDate = dateTxt.getText()的toString();
                                字符串updatedComments = commentsTxt.getText()的toString()。                                UpdateArtistButton(updatedName,updatedVenue,updatedDate,updatedComments);
                            }
                        }
                    });                }而(c.moveToNext());
            }
        }        赶上(的SQLException E)
        {
            e.printStackTrace();
        }
    }    公共无效UpdateArtistButton(字符串passedName,字符串passedVenue,字符串passedDate,字符串passedComments)
    {
        尝试
        {
            db.open();
            Log.i(测试,更新艺术家方法:名称=价值+ passedName);
            Log.i(测试,更新艺术家方法:场地=价值+ passedVenue);
            Log.i(测试,更新艺术家方法:日期=价值+ passedDate);
            Log.i(测试,更新艺术家方法:注释=值+ passedComments);
            db.updateConcert(passedName,passedVenue,passedDate,passedComments);
            Toast.makeText(UpdateArtist.this!演唱会更新,Toast.LENGTH_LONG).show();
            super.finish();
        }        赶上(的SQLException E)
        {
            e.printStackTrace();
        }        db.close();
    }
}

下面是DBManager类:

 包com.example.msdproject;进口android.content.ContentValues​​;
进口android.database.Cursor;
进口android.database.sqlite.SQLiteDatabase;
进口android.database.sqlite.SQLiteOpenHelper;
进口android.content.Context;
进口android.util.Log;进口值java.sql.SQLException;
公共类DBManager {    公共静态最后弦乐COL_ROWID =_id;
    公共静态最后弦乐COL_NAME =名;
    公共静态最后弦乐COL_VENUE =场地;
    公共静态最后弦乐COL_DATE =日期;
    公共静态最后弦乐COL_COMMENTS =意见;    私有静态最后弦乐DB_NAME =音乐会;
    私有静态最后弦乐DB_TABLE =Concert_Info;
    私有静态最终诠释DB_VERSION = 1;    私有静态最后弦乐DB_CREATE =
            CREATE TABLE+ DB_TABLE +
    (_id整数主键自动增量,+
            名称的文本不为空,+
            场地文本不为空,+
            意见文本不为空,+
            日期文本不是null);;    私人最终上下文的背景下;    私人DatabaseHelper DBHelper;
    私人SQLiteDatabase分贝;    公共DBManager(上下文CTX)
    {
        this.context = CTX;
        DBHelper =新DatabaseHelper(背景);
    }    公共静态类DatabaseHelper扩展SQLiteOpenHelper
    {
        DatabaseHelper(上下文的背景下)
        {
            超(背景下,DB_NAME,空,DB_VERSION);
        }        @覆盖
        公共无效的onCreate(SQLiteDatabase DB)
        {
            db.execSQL(DB_CREATE);
        }        @覆盖
        公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页)
        {
            / *
            //从YouTube视频教程采取
            Log.w(TAG,从版本升级数据库+ oldVersion +到
                    + NEWVERSION +,这将摧毁所有旧数据);
            db.execSQL(是否存在Concert_Info删除表);
            的onCreate(DB); * /
        }
    }    公共DBManager的open()抛出的SQLException
    {
        DB = DBHelper.getWritableDatabase();
        //db.execSQL(\"DROP表,如果存在+ DB_TABLE +);
        返回此;
    }    公共无效的close()
    {
        DBHelper.close();
    }    众长insertConcert(字符串名称,字符串地点,日期字符串,字符串评论)
    {
        ContentValues​​ initialValues​​ =新ContentValues​​();
        initialValues​​.put(COL_NAME,名);
        initialValues​​.put(COL_VENUE,地点);
        initialValues​​.put(COL_DATE,日期);
        initialValues​​.put(COL_COMMENTS,评论);
        返回db.insert(DB_TABLE,空,initialValues​​);
    }    公共布尔deleteConcert(字符串名称)
    {
        返回db.delete(DB_TABLE,COL_NAME +=+名,NULL)> 0;
    }    公共光标getAllConcerts(){
        返回db.query(DB_TABLE,新的String []
                        {
                                COL_ROWID,
                                COL_NAME,
                                COL_VENUE,
                                COL_DATE,
                                COL_COMMENTS
                        },
                        空值,
                        空值,
                        空值,
                        空值,
                        空值,
                        空值
                );
    }    公共光标getConcert(长ROW_ID)抛出的SQLException
    {
        光标mCursor =
                db.query(DB_TABLE,新的String []
                        {
                                COL_ROWID,
                                COL_NAME,
                                COL_VENUE,
                                COL_DATE,
                                COL_COMMENTS
                        },
                        COL_ROWID +=+ ROW_ID,
                        空值,
                        空值,
                        空值,
                        空值
                );
        如果(mCursor!= NULL)
        {
            mCursor.moveToFirst();
        }        返回mCursor;
    }    公共布尔updateConcert(字符串名称,字符串地点,日期字符串,字符串评论)
    {
        ContentValues​​ updateValues​​ =新ContentValues​​();
        updateValues​​.put(COL_NAME,名);
        updateValues​​.put(COL_VENUE,地点);
        updateValues​​.put(COL_DATE,日期);
        updateValues​​.put(COL_COMMENTS,评论);
        Log.i(测试,DB经理方法:名称=价值+姓名);
        Log.i(测试,DB管理方法:场地=价值+场地);
        Log.i(测试,DB管理方法:日期=价值+日期);
        Log.i(测试,DB管理方法:注释=值+评论);
        返回db.update(DB_TABLE,updateValues​​,姓名+=+名,NULL)> 0;
    }    公共无效复位()抛出的SQLException {
        db.delete(DB_TABLE,NULL,NULL);
        db.close();
        this.DBHelper.onCreate(this.db);
    }
}


解决方案

值应该被引用:

 返回db.update(DB_TABLE,updateValues​​,姓名+=+名字+',NULL)> 0

My database contains a list of concerts and I'm updating them based on the name column. When the update button is clicked, the column values of the given concert is passed in. However the update only works when the name column is a single number. If the name column is a string, or 2+ digit number, it crashes instantly and gives me the following errors.

11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ Update artist method: Value of name = test
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ Update artist method: Value of venue = test venue
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ Update artist method: Value of date = dd
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ Update artist method: Value of comments = d
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ DB Manager method: Value of name = test
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ DB Manager method: Value of venue = test venue
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ DB Manager method: Value of date = dd
11-17 13:14:51.325  12131-12131/com.example.msdproject I/test﹕ DB Manager method: Value of comments = d
11-17 13:14:51.325  12131-12131/com.example.msdproject E/SQLiteLog﹕ (1) no such column: test
11-17 13:14:51.335  12131-12131/com.example.msdproject D/AndroidRuntime﹕ Shutting down VM
11-17 13:14:51.335  12131-12131/com.example.msdproject W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41614ba8)
11-17 13:14:51.355  12131-12131/com.example.msdproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.msdproject, PID: 12131
    android.database.sqlite.SQLiteException: no such column: test (code 1): , while compiling: UPDATE Concert_Info SET date=?,venue=?,comments=?,name=? WHERE name=test
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1572)
        at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1520)
        at com.example.msdproject.DBManager.updateConcert(DBManager.java:150)
        at com.example.msdproject.UpdateArtist.UpdateArtistButton(UpdateArtist.java:103)
        at com.example.msdproject.UpdateArtist$1.onClick(UpdateArtist.java:79)
        at android.view.View.performClick(View.java:4438)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
11-17 13:14:51.365  12131-12131/com.example.msdproject D/dalvikvm﹕ GC_FOR_ALLOC freed 591K, 4% free 17167K/17788K, paused 9ms, total 9ms
11-17 13:14:53.245  12903-12903/com.example.msdproject I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13
11-17 13:14:53.275  12903-12903/com.example.msdproject D/OpenGLRenderer﹕ Enabling debug mode 0

What it is basically saying is that the column doesn't exist but I can't see why it's giving me this error as it recognises the column exists when I use a single number. I tried deleting by _id but that gave me the same result so I reverted back to deleting by the name column. Are there exceptions as to what can be passed into a database update function?

Here is the updateArtist class:

package com.example.msdproject;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.sql.SQLException;

public class UpdateArtist extends Activity {

    DBManager db = new DBManager(this);

    public EditText nameTxt;
    public EditText venueTxt;
    public EditText dateTxt;
    public EditText commentsTxt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_artist);

        Intent intent = getIntent();
        final long num = intent.getLongExtra("id", 1);

        try {
            db.open();
            Cursor c = db.getConcert(num);
            if (c.moveToFirst())
            {
                do
                {
                    String name = (c.getString(1));
                    String venue = (c.getString(2));
                    String date = (c.getString(3));
                    String comments = (c.getString(4));

                    TextView titleTxt = (TextView)findViewById(R.id.updateTitle);
                    nameTxt = (EditText)findViewById(R.id.updateName);
                    venueTxt = (EditText)findViewById(R.id.updateVenue);
                    dateTxt = (EditText)findViewById(R.id.updateDate);
                    commentsTxt = (EditText)findViewById(R.id.updateComments);


                    titleTxt.setText(name);
                    nameTxt.setText(name);
                    venueTxt.setText(venue);
                    dateTxt.setText(date);
                    commentsTxt.setText(comments);

                    Button update = (Button)findViewById(R.id.updateConcertButton);
                    update.setOnClickListener(new View.OnClickListener()
                    {
                        @Override
                        public void onClick(View v)
                        {
                            if (nameTxt.getText().toString().isEmpty()  || venueTxt.getText().toString().isEmpty() ||
                                    dateTxt.getText().toString().isEmpty() || commentsTxt.getText().toString().isEmpty() )
                            {
                                Toast.makeText(UpdateArtist.this, "Error! Please fill in all fields", Toast.LENGTH_LONG).show();
                            }
                            else
                            {

                                String updatedName = nameTxt.getText().toString();
                                String updatedVenue = venueTxt.getText().toString();
                                String updatedDate = dateTxt.getText().toString();
                                String updatedComments = commentsTxt.getText().toString();

                                UpdateArtistButton(updatedName,updatedVenue,updatedDate,updatedComments);
                            }
                        }
                    });

                } while (c.moveToNext());
            }
        }

        catch (SQLException e)
        {
            e.printStackTrace();
        }
    }

    public void UpdateArtistButton(String passedName, String passedVenue, String passedDate, String passedComments)
    {
        try
        {
            db.open();
            Log.i("test", "Update artist method: Value of name = " + passedName);
            Log.i("test", "Update artist method: Value of venue = " + passedVenue);
            Log.i("test", "Update artist method: Value of date = " + passedDate);
            Log.i("test", "Update artist method: Value of comments = " + passedComments);
            db.updateConcert(passedName,passedVenue, passedDate, passedComments);
            Toast.makeText(UpdateArtist.this, "Concert Updated!", Toast.LENGTH_LONG).show();
            super.finish();
        }

        catch (SQLException e)
        {
            e.printStackTrace();
        }

        db.close();
    }
}

Here is the DBManager class:

package com.example.msdproject;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.util.Log;

import java.sql.SQLException;


public class DBManager {

    public static final String COL_ROWID = "_id";
    public static final String COL_NAME = "name";
    public static final String COL_VENUE = "venue";
    public static final String COL_DATE = "date";
    public static final String COL_COMMENTS = "comments";

    private static final String DB_NAME = "Concerts";
    private static final String DB_TABLE = "Concert_Info";
    private static final int DB_VERSION = 1;

    private static final String DB_CREATE =
            "create table " + DB_TABLE + 
    " (_id integer primary key autoincrement, " +
            "name text not null, " +
            "venue text not null, " +
            "comments text not null, " +
            "date text not null);";

    private final Context context;

    private DatabaseHelper DBHelper;
    private SQLiteDatabase db;

    public DBManager(Context ctx)
    {
        this.context = ctx;
        DBHelper = new DatabaseHelper(context);
    }

    public static class DatabaseHelper extends SQLiteOpenHelper
    {
        DatabaseHelper(Context context)
        {
            super(context, DB_NAME, null, DB_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL(DB_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            /*
            //taken from YouTube Tutorial video
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                    + newVersion + ", which will destroy all old data");
            db.execSQL("drop table if exists Concert_Info");
            onCreate(db);*/
        }
    }

    public DBManager open() throws SQLException
    {
        db = DBHelper.getWritableDatabase();
        //db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE + ";");
        return this;
    }

    public void close()
    {
        DBHelper.close();
    }

    public long insertConcert(String name, String venue, String date, String comments)
    {
        ContentValues initialValues = new ContentValues();
        initialValues.put(COL_NAME, name);
        initialValues.put(COL_VENUE, venue);
        initialValues.put(COL_DATE, date);
        initialValues.put(COL_COMMENTS, comments);
        return db.insert(DB_TABLE, null, initialValues);
    }

    public boolean deleteConcert(String name)
    {
        return db.delete(DB_TABLE, COL_NAME + "=" + name, null) > 0;
    }

    public Cursor getAllConcerts() {
        return db.query(DB_TABLE, new String[]
                        {
                                COL_ROWID,
                                COL_NAME,
                                COL_VENUE,
                                COL_DATE,
                                COL_COMMENTS
                        },
                        null,
                        null,
                        null,
                        null,
                        null,
                        null
                );
    }

    public Cursor getConcert(long ROW_ID) throws SQLException
    {
        Cursor mCursor =
                db.query(DB_TABLE, new String[]
                        {
                                COL_ROWID,
                                COL_NAME,
                                COL_VENUE,
                                COL_DATE,
                                COL_COMMENTS
                        },
                        COL_ROWID + "=" + ROW_ID,
                        null,
                        null,
                        null,
                        null
                );
        if (mCursor != null)
        {
            mCursor.moveToFirst();
        }

        return mCursor;
    }

    public boolean updateConcert(String name, String venue, String date, String comments)
    {
        ContentValues updateValues = new ContentValues();
        updateValues.put(COL_NAME, name);
        updateValues.put(COL_VENUE, venue);
        updateValues.put(COL_DATE, date);
        updateValues.put(COL_COMMENTS, comments);
        Log.i("test", "DB Manager method: Value of name = " + name);
        Log.i("test", "DB Manager method: Value of venue = " + venue);
        Log.i("test", "DB Manager method: Value of date = " + date);
        Log.i("test", "DB Manager method: Value of comments = " + comments);
        return db.update(DB_TABLE, updateValues, "name"  + "=" + name, null) > 0;
    }

    public void reset () throws SQLException {
        db.delete(DB_TABLE, null, null);
        db.close();
        this.DBHelper.onCreate(this.db);
    }
}

解决方案

value should be quoted:

return db.update(DB_TABLE, updateValues, "name"  + "='" + name +"'", null) > 0

这篇关于安卓:错误使用字符串更新数据库时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆