gpt4 book ai didi

java - 无法将数据插入 SQLite 表

转载 作者:搜寻专家 更新时间:2023-11-01 09:11:23 25 4
gpt4 key购买 nike

我需要在表中插入一些值,但它给了我这个异常:

Android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x2e51a0

以下是我的代码:

public static final String DATABASE_NAVIGATION_CREATE = "create table navigation (KEY text,TYPE1 text,LINK_NAME text,DISPLAY_NAME text,FORWARD_ICON text,HIGHLIGHTED_ICON_WITH_TEXT text,ICON_WITHOUT_TEXT text,HIGHLIGHTED_ICON_WITHOUT_TEXT text,Banner_Image text,CHILDREN text,ICON_WITH_TEXT text)";

database.execSQL(DATABASE_NAVIGATION_CREATE);
private static final String INSERT_NAVIGATION = "insert into "
+ DATABASE_TABLE_NAVIGATION + "(KEY,TYPE1,LINK_NAME,DISPLAY_NAME,FORWARD_ICON,HIGHLIGHTED_ICON_WITH_TEXT,ICON_WITHOUT_TEXT,HIGHLIGHTED_ICON_WITHOUT_TEXT,Banner_Image,CHILDREN,ICON_WITH_TEXT)"+
" values (?,?,?,?,?,?,?,?,?,?,?)";

public WineDatabaseAdapter(Context context) {
try{
this.context = context;
openHelper = new WineDatabaseHelper(context);
this.db=openHelper.getWritableDatabase();
this.insertStmt=this.db.compileStatement(INSERT_NAVIGATION);
this.insertStmt=this.db.compileStatement(INSERT_ICON);
this.insertStmt=this.db.compileStatement(INSERT);
} catch(Exception e) {
System.out.println(e);
}
}

public long insertNavigation(String KEY ,String TYPE1,String LINK_NAME,String DISPLAY_NAME,String FORWARD_ICON,String HIGHLIGHTED_ICON_WITH_TEXT,String ICON_WITHOUT_TEXT,String HIGHLIGHTED_ICON_WITHOUT_TEXT,String Banner_Image,String CHILDREN,String ICON_WITH_TEXT ){
this.insertStmt.bindString(1, KEY);
this.insertStmt.bindString(2, TYPE1);
this.insertStmt.bindString(3, LINK_NAME);

this.insertStmt.bindString(4, DISPLAY_NAME);
this.insertStmt.bindString(5, FORWARD_ICON);
this.insertStmt.bindString(6, HIGHLIGHTED_ICON_WITH_TEXT);
this.insertStmt.bindString(7, ICON_WITHOUT_TEXT);
this.insertStmt.bindString(8, HIGHLIGHTED_ICON_WITHOUT_TEXT);
this.insertStmt.bindString(9, Banner_Image);
this.insertStmt.bindString(10, CHILDREN);
this.insertStmt.bindString(11, ICON_WITH_TEXT);

return this.insertStmt.executeInsert();
}


JSONObject objJson=navigation.getJSONObject(navigation_object);
key= navigation_object;

System.out.println(key+" this is the key");
try{
display_name=objJson.getString("display_name");
System.out.println(display_name);
} catch(Exception e){
System.out.println(e);
}
try{
type=objJson.getString("type");
System.out.println("type is "+type);
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
try{
banner_image=objJson.getString("banner_image");
System.out.println(banner_image+"*********banner_image ************");
} catch(Exception e) {
System.out.println(e);
}
try{
link_name=objJson.getString("link_name");
System.out.println("link_name**********"+link_name);
} catch(Exception e){
System.out.println(e);
}
try{
forward_icon=objJson.getString("forward_icon");
System.out.println("forward_icon***********"+forward_icon);
} catch (Exception e) {
System.out.println(e);
}
try{
highlighted_icon_with_text= objJson.getString("highlighted_icon_with_text");
System.out.println(highlighted_icon_with_text+"*****************highlighted_icon_with_text");
} catch (Exception e) {
System.out.println(e);
}
try{
children1= objJson.getString("children");
System.out.println("children1"+children1+"******************");
} catch (Exception e) {
System.out.println(e);
}
try{
icon_without_text= objJson.getString("icon_without_text");
System.out.println("icon_without_text*************"+icon_without_text);
} catch (Exception e) {
System.out.println(e);
}
try{
highlighted_icon_without_text=objJson.getString("highlighted_icon_without_text");
System.out.println("highlighted_icon_without_text ***************** "+highlighted_icon_without_text);
} catch (Exception e) {
System.out.println(e);
}
try{
icon_with_text=objJson.getString("icon_with_text");
System.out.println("icon_with_text******"+icon_with_text);
}catch(Exception e) {
System.out.println(e);
}

db.insertNavigation(key, type, link_name, display_name, forward_icon, highlighted_icon_with_text, icon_without_text, highlighted_icon_without_text, banner_image, children1, icon_with_text);

最佳答案

这是一个远景,但我认为值得一试。 “KEY”是 SQL 的特殊关键字,因此,请尝试将列名 KEY 重命名为创建数据库和插入脚本中的其他名称。

关于java - 无法将数据插入 SQLite 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076346/

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