Reputation: 2227
I need to insert some values in a table but it is giving me this exception:
Android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x2e51a0
Following is my code:
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);
Upvotes: 2
Views: 719
Reputation: 19250
Make sure,you are using proper field names.It seems that you might try to use String variable names as field names in you query.
Ex.: public final String DISPLAY_NAME="display_name";
And you are trying to use DISPLAY_NAME as field name,instead of "display_name". That will require modification in your query. Android might not be able to find the field name you specified in your query.
Upvotes: 0
Reputation: 59168
This is a long shot but I think it is worth trying. "KEY" is a special keyword for SQL so, try renaming the column name KEY
to something else in your create db & insert script.
Upvotes: 3