gpt4 book ai didi

java - 使用自定义查询更新,rawQuery 或 execSQL 不起作用

转载 作者:行者123 更新时间:2023-12-01 14:07:24 24 4
gpt4 key购买 nike

我正在使用个人查询来更新表中的值,在本例中是增加某些列的值。例如,我会做类似的事情:

UPDATE statistica SET 1PF = 1PF + ? WHERE id_statistica = ?;

我的代码如下:

String sql = "UPDATE " + StatisticaTable.TABLE_NAME + " SET " + StatisticaTable._1PF + " = " + StatisticaTable._1PF + " + ?, " +
StatisticaTable._1PN + " = " + StatisticaTable._1PN + " + ?, " +
StatisticaTable._2PF + " = " + StatisticaTable._2PF + " + ?, " +
StatisticaTable._2PN + " = " + StatisticaTable._2PN + " + ?, " +
StatisticaTable._3PF + " = " + StatisticaTable._3PF + " + ?, " +
StatisticaTable._3PN + " = " + StatisticaTable._3PN + " + ?, " +
StatisticaTable.RD + " = " + StatisticaTable.RD + " + ?, " + StatisticaTable.RO + " = " + StatisticaTable.RO + " + ?, " +
StatisticaTable.PR + " = " + StatisticaTable.PR + " + ?, " + StatisticaTable.AS + " = " + StatisticaTable.AS + " + ?, " +
StatisticaTable.BK + " = " + StatisticaTable.BK + " + ?, " + StatisticaTable.FS + " = " + StatisticaTable.FS + " + ?, " +
StatisticaTable.PP + " = " + StatisticaTable.PP + " + ?, " + StatisticaTable.FP + " = " + StatisticaTable.FP + " + ? " +
"WHERE " + GiocatoreTable.ID_GIOCATORE + "= ? AND + " + StatisticaTable.ID_PARTITA + "= ?;";

String[] parameter = new String[] {String.valueOf(values.get1pf()), String.valueOf(values.get1pn()), String.valueOf(values.get2pf()), String.valueOf(values.get2pn()),
String.valueOf(values.get3pf()), String.valueOf(values.get3pn()), String.valueOf(values.getRD()), String.valueOf(values.getRO()), String.valueOf(values.getPR()),
String.valueOf(values.getAS()), String.valueOf(values.getBK()), String.valueOf(values.getFS()),
String.valueOf(values.getPP()), String.valueOf(values.getFP()), String.valueOf(values.getIDGiocatore()), String.valueOf(values.getIDPartita())};

_dbHelper.getWritableDatabase().execSQL(sql, parameter);

本质上,代码是这样的...但不更新任何内容(既使用 execSQL rawQuery),尽管参数已正确传递并且 sql 字符串以正确的方式形成...我不明白出了什么问题......

最佳答案

如果您没有收到任何 SQL 异常,那么也许您应该关注 WHERE 语句。

"WHERE " + GiocatoreTable.ID_GIOCATORE + "= ? AND + " + StatisticaTable.ID_PARTITA + "= ?;";

SQLite 有时可能有点棘手,因为它只使用五种基本数据类型。我注意到,如果存储的数据库值和,WHERE 语句可能会失败搜索参数有不同的类型。尝试转换ID_GIOCATORE参数并将 ID_PARTITA 参数转换为数据库中使用的 native 类型。

http://www.sqlite.org/datatype3.html

关于java - 使用自定义查询更新,rawQuery 或 execSQL 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794996/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com