Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 更新选定列中的数据库_Android_Android Sqlite_Android Preferences - Fatal编程技术网

Android 更新选定列中的数据库

Android 更新选定列中的数据库,android,android-sqlite,android-preferences,Android,Android Sqlite,Android Preferences,我需要更新数据库中选定的列 这是我的db适配器类 public class DBAdapter { private static final String TAG = "DBAdapter"; private static final String DATABASE_NAME = "jobDiagnosis"; private static final int DATABASE_VERSION = 2; Cursor cursor = null; private static final St

我需要更新数据库中选定的列 这是我的db适配器类

public class DBAdapter {

private static final String TAG = "DBAdapter";
private static final String DATABASE_NAME = "jobDiagnosis";
private static final int DATABASE_VERSION = 2;
Cursor cursor = null;
private static final String TABLE_DATA = "create table Job_Saved (" +
        "Id text not null," +
        "Title text not null," +
        "Location text not null," +
        "State text not null," +
        "Company text not null," +
        "Description text not null," +
        "Status text not null," +
        "Username text not null," +
        "Password text not null)";
private final Context context;
private DatabaseHelper dbHelper;
private SQLiteDatabase db;
private static DBAdapter instance;

private DBAdapter(Context c) {
    System.out.println("Constructor of DB Adapter...");
    this.context = c;
    System.out.println("Creating the object of db helper class..");
    try
    {
    dbHelper = new DatabaseHelper(context);
    dbHelper.getWritableDatabase();
    }
    catch (Exception e) {
        // TODO: handle exception
        Log.d("err", ""+e);
    }
}

public static DBAdapter getInstance(Context C) {
    if (null == instance) {
        instance = new DBAdapter(C);
    }
    return instance;
}

public void openReadableDatabase() throws SQLException {
    db = dbHelper.getReadableDatabase();
}

public void openWritableDatabase() throws SQLException {
    db = dbHelper.getWritableDatabase();

}


public void close() {
    dbHelper.close();   
}   
public long DeleteLocation()
{
    return db.delete("Job_Saved", null, null);
}
public long DeleteLocation(String id)
{
    return db.delete("Job_Saved", "id='" + id + "'", null);
}
public long updateLocation(String id,String str)
{
    return db.update("Job_saved", null, "Id='" + id + "'"+"& "+"Status='" + str + "'", null);
}
public long insertlocation(String Id,String Title,String Location,String State,String Company,String Description,String value, String Username,String Password) {
    //DatabaseHelper d=new DatabaseHelper(DBAdapter.this);
    ContentValues initialValues = new ContentValues();
    initialValues.put("Id", Id);
    initialValues.put("Title", Title);
    initialValues.put("Location", Location);
    initialValues.put("State", State);
    initialValues.put("Company",Company);
    initialValues.put("Description", Description);
    initialValues.put("Status", value);
    initialValues.put("Username", Username);
    initialValues.put("Password", Password);
    return db.insert("Job_Saved", null, initialValues);
}
public ArrayList<Data> getAllData(String username){
    ArrayList<Data> arr = new ArrayList<Data>();
    Cursor c = db.query("Job_Saved", null, "Username='" + username + "'", null, null, null, null);  
    if(c.getCount()>0){
        while(c.moveToNext()){
            Data f = new Data();
            f.setid(c.getString(0));
            f.setbusinessname(c.getString(1));
            f.setcityname(c.getString(2));
            f.setstatename(c.getString(3));
            f.setcompanyname(c.getString(4));
            f.setDesc(c.getString(5));
            f.setStatus(c.getString(6));
            f.setUser(c.getString(7));
            //f.setCharging(c.getString(8));
            arr.add(f);
        }

    }
    c.close();
    return arr;
}
public Boolean getStatus(String str){
    Boolean check_status=false;
    Cursor c = db.query("Job_Saved", null, "id='" + str + "'", null, null, null, null); 
    if(c.getCount()>0){
    check_status=true;
    }
    c.close();
    return check_status;
}
public boolean getStatus(String str,String username){
    Boolean check_status=false;
    Cursor c = db.query("Job_Saved", null, "Id='" + str + "'"+" & "+"Username='" + str + "'", null, null, null, null);  
    while(c.getCount()>0){
    check_status=true;
    }
    c.close();
    return check_status;
}
public void updateDownload(String id  , String status)
{
    ContentValues initialValues = new ContentValues();
    initialValues.put("status", status);
    db.update("Likes", initialValues, "id=?", new String[] {id});
}
public String getIdStatus(String id){
    String a="";
    Cursor c =  db.query("Likes", null, "id='" + id + "'", null, null, null,
            null);      
    if(c.getCount()>0){
        while(c.moveToNext())
        {
         a=c.getString(1);
        }

    }
    return a;
}
公共类DBAdapter{
私有静态最终字符串TAG=“DBAdapter”;
私有静态最终字符串数据库\u NAME=“jobDiagnosis”;
私有静态最终int数据库_VERSION=2;
游标=空;
私有静态最终字符串TABLE\u DATA=“创建表作业”已保存(“+
Id文本不为空+
标题文本不为空+
位置文本不为空+
状态文本不为空+
公司文本不为空+
说明文本不为空+
状态文本不为空+
用户名文本不为空+
“密码文本不为空)”;
私人最终语境;
私有数据库助手dbHelper;
专用数据库数据库;
私有静态DBAdapter实例;
专用DBAdapter(上下文c){
System.out.println(“DB适配器的构造函数…”);
this.context=c;
System.out.println(“创建db helper类的对象…”);
尝试
{
dbHelper=新数据库助手(上下文);
dbHelper.getWritableDatabase();
}
捕获(例外e){
//TODO:处理异常
Log.d(“err”和“+e”);
}
}
公共静态DBAdapter getInstance(上下文C){
if(null==实例){
实例=新的DBAdapter(C);
}
返回实例;
}
public void openReadableDatabase()引发SQLException{
db=dbHelper.getReadableDatabase();
}
public void openwriteabledatabase()引发SQLException{
db=dbHelper.getWritableDatabase();
}
公众假期结束(){
dbHelper.close();
}   
公共长删除位置()
{
返回db.delete(“作业已保存”,null,null);
}
公共长删除位置(字符串id)
{
返回db.delete(“已保存作业”,“id=”+id+”,null);
}
公共长更新位置(字符串id、字符串str)
{
返回db.update(“Job_saved”,null,“Id=”“+Id+””“+”&“+”Status=”“+str+””,null);
}
公共长插入位置(字符串Id、字符串标题、字符串位置、字符串状态、字符串公司、字符串描述、字符串值、字符串用户名、字符串密码){
//DatabaseHelper d=新的DatabaseHelper(DBAdapter.this);
ContentValues initialValues=新的ContentValues();
initialValues.put(“Id”,Id);
初始值。放置(“标题”,标题);
初始值。放置(“位置”,位置);
initialValues.put(“State”,State);
初始值。卖出(“公司”,公司);
初始值。输入(“说明”,说明);
初始值。输入(“状态”,值);
initialValues.put(“用户名”,Username);
initialValues.put(“密码”,Password);
返回db.insert(“作业已保存”,null,初始值);
}
公共ArrayList getAllData(字符串用户名){
ArrayList arr=新的ArrayList();
游标c=db.query(“已保存作业”,null,“用户名=”+“用户名+””,null,null,null,null);
如果(c.getCount()>0){
while(c.moveToNext()){
数据f=新数据();
f、 setid(c.getString(0));
f、 setbusinessname(c.getString(1));
f、 setcityname(c.getString(2));
f、 setstatename(c.getString(3));
f、 setcompanyname(c.getString(4));
f、 setDesc(c.getString(5));
f、 setStatus(c.getString(6));
f、 setUser(c.getString(7));
//f、 设置充电(c.getString(8));
arr.add(f);
}
}
c、 close();
返回arr;
}
公共布尔getStatus(字符串str){
布尔检查_状态=false;
游标c=db.query(“已保存作业”,null,“id=”+str+“”,null,null,null,null);
如果(c.getCount()>0){
检查_status=true;
}
c、 close();
返回检查状态;
}
公共布尔getStatus(字符串str、字符串用户名){
布尔检查_状态=false;
游标c=db.query(“作业已保存”,null,“Id=”+str+“””“+”&“+”用户名=”+str+“”,null,null,null);
而(c.getCount()>0){
检查_status=true;
}
c、 close();
返回检查状态;
}
public void updateDownload(字符串id、字符串状态)
{
ContentValues initialValues=新的ContentValues();
初始值。放置(“状态”,状态);
update(“Likes”,initialValues,“id=?”,新字符串[]{id});
}
公共字符串getIdStatus(字符串id){
字符串a=“”;
游标c=db.query(“Likes”,null,“id=”“+id+”””,null,null,null,
无效);
如果(c.getCount()>0){
while(c.moveToNext())
{
a=c.getString(1);
}
}
返回a;
}
我想更新if的状态基,但无法创建更新方法 我是android开发的新手

请帮帮我 PLz检查更新定位方法

我真的很抱歉我的英语不好


提前感谢

使用
ContentValues
提供更新方法的值

public long updateLocation(String id,String str)
{
    ContentValues values = new ContentValues();
    values.put("Status", str);

    return db.update("Job_Saved", values, "Id='" + id + "'", null);
}
注意:最好在
WHERE
子句中使用参数化语句来防止SQL注入

return db.update("Job_Saved", values, "Id=?", new String[]{ id });

PLZ check UpdateLocation Method…你能澄清你的问题吗?你想更新给定ID的状态吗?是的,我们想更新给定ID的状态当我使用此代码时,出现错误类型SQLITEDABASE中的方法update(String,ContentValues,String,String[])不适用于参数(String,String[],字符串[],内容值)