Android sqlite更新失败

时间:2013-05-11 05:00:11

标签: android sqlite

我有以下表结构

public class DBConnectionTableTVShow {
    public static final String SHOWID = "show_id";
    public static final String SHOWNAME = "show_name";
    public static final String SHOWSEASON = "season_name";
    public static final String EPISODENAME = "episode_name";
    public static final String EPISODESTATUS = "episode_status";

    public static final String DBNAME = "entertainment_tracker";
    public static final String DBTABLE = "tv_show";
    public static final int VERSION = 1;
}

现在我要更新episode_status

我创建了以下方法

public void updateEpisodeStatus(String showName, String seasonName, String episodeNo, String epStat) {
     db.execSQL("UPDATE tv_show SET " +
                "episode_status='"+epStat+"'"+
                "WHERE show_name='"+showName+"' " +
                "AND season_name='"+seasonName+"' " +
                "AND episode_name='"+episodeNo+"'", 
                null);
}

当我尝试使用此方法时,我收到错误:

  

java.lang.IllegalArgumentException:清空bindArgs

如何解决这个问题?

3 个答案:

答案 0 :(得分:2)

删除您传递为null的第二个参数,它将起作用。

public void updateEpisodeStatus(String showName, String seasonName, String episodeNo, String epStat) {
     db.execSQL("UPDATE tv_show SET " +
                "episode_status='"+epStat+"'"+
                "WHERE show_name='"+showName+"' " +
                "AND season_name='"+seasonName+"' " +
                "AND episode_name='"+episodeNo+"'");
}

答案 1 :(得分:1)

您不能使用execSql来上传数据。它执行的单个SQL语句不是SELECT/INSERT/UPDATE/DELETE

您应该使用Update Method来更新数据库。

答案 2 :(得分:1)

像那样使用

String query =“update tv_show SET episode_status = epStat where show_name = showName and season_name = seasonName”; db.rowquery(query,null);