gpt4 book ai didi

java - 无列名 - 创建后

转载 作者:行者123 更新时间:2023-11-29 03:31:47 25 4
gpt4 key购买 nike

我确信我做错了什么,但在投入大量时间后未能确定是什么。简而言之,错误是某个列不存在,但我之前创建了它:

static final String itemTable="ITEMS";
static final String colItemID="ItemID";
static final String colItemName="ItemName";
static final String colQuantity="ItemQuantity";
static final String colPrice="ItemPrice";
static final String colCategory="ItemCategory";
static final String colAisle="ItemAisle";
static final String colCreator="ItemCreator";
static final String colActMemID="ItemActivityMemberID";
static final String colDate="ItemDate";
static final String colHistory="ItemHistory";
static final String colPicture="ItemPicture";

建表命令:

try {
db.execSQL("CREATE TABLE " + itemTable + " " + "(" + colItemID +
" INTEGER PRIMARY KEY AUTOINCREMENT, " + colItemName + " TEXT, " +
colQuantity + " Integer, " + colPrice + "REAL, " + colCategory + " TEXT, "
+ colAisle + " TEXT, " + colCreator + " TEXT, " + colActMemID + " TEXT, " +
colDate + " TEXT, " + colHistory + " TEXT, " + colPicture + " TEXT)");
} catch (SQLException e) {
System.out.println(e);
}

然后,当我尝试创建 View 时:

try {
db.execSQL("CREATE VIEW "+viewList+
" AS SELECT "+itemTable+"."+colItemID+" AS _id,"+
" "+itemTable+"."+colItemName+","+
" "+itemTable+"."+colPrice+","+
" "+itemTable+"."+colQuantity+","+

" "+membersTable+"."+colMemName+""+
" FROM "+itemTable+" JOIN "+membersTable+
" ON "+itemTable+"."+colActMemID+" ="+membersTable+"."+colMemID
);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(e);
}

他提示了一个特定的专栏:

07-22 10:33:26.548: I/System.out(1753): back from db construct
07-22 10:33:26.628: E/SQLiteLog(1753): (1) no such column: ITEMS.ItemPrice
07-22 10:33:26.638: D/AndroidRuntime(1753): Shutting down VM
07-22 10:33:26.638: W/dalvikvm(1753): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-22 10:33:26.688: E/AndroidRuntime(1753): FATAL EXCEPTION: main
07-22 10:33:26.688: E/AndroidRuntime(1753): android.database.sqlite.SQLiteException: no such
column: ITEMS.ItemPrice (code 1): , while compiling: CREATE VIEW ViewList AS SELECT ITEMS.ItemID
AS _id, ITEMS.ItemName, ITEMS.ItemPrice, ITEMS.ItemQuantity, MEMBERS.MemberName FROM ITEMS JOIN
MEMBERS ON ITEMS.ItemActivityMemberID =MEMBERS.MemberID
07-22 10:33:26.688: E/AndroidRuntime(1753): at
android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
07-22 10:33:26.688: E/AndroidRuntime(1753): at
android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
07-22 10:33:26.688: E/AndroidRuntime(1753): at
android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
07-22 10:33:26.688: E/AndroidRuntime(1753): at android.database.sqlite.SQLiteSession.prepare
(SQLiteSession.java:588)

我尽可能多地查看了答案,但没有找到任何线索,非常感谢您的帮助!

谢谢,

加仑

最佳答案

您在 colPrice 之后缺少一个空格字符,因此列名称将改为 ItemPriceREAL。改为

try {
db.execSQL("CREATE TABLE " + itemTable + " " + "(" + colItemID +
" INTEGER PRIMARY KEY AUTOINCREMENT, " + colItemName + " TEXT, " +
colQuantity + " Integer, " + colPrice + " REAL, " + colCategory + " TEXT, "
+ colAisle + " TEXT, " + colCreator + " TEXT, " + colActMemID + " TEXT, " +
colDate + " TEXT, " + colHistory + " TEXT, " + colPicture + " TEXT)");
} catch (SQLException e) {
System.out.println(e);
}

通常,在构建 SQL 查询以防止 SQL injection 时,最好避免 String 连接攻击。在这种情况下,它(将查询作为单个 String 文字)会突出显示缺少的空间。

关于java - 无列名 - 创建后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17785841/

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