android - SQLite database problems, Really unsure -


im trying create simple database using sqlite , im coming error when running application. app runs fine, until press button save data database, error message im getting is..

04-19 13:47:00.492 26807-26807/com.example.bash1.sqlitediss e/openglrenderer: getting max_texture_size gradiencache 04-19 13:47:00.500 26807-26807/com.example.bash1.sqlitediss e/openglrenderer: max_texture_size: 16384 04-19 13:47:00.520 26807-26807/com.example.bash1.sqlitediss e/openglrenderer: getting max_texture_size caches::initconstraints() 04-19 13:47:31.164 26807-26807/com.example.bash1.sqlitediss e/sqlitelog: (1) near "tablestock_table": syntax error 04-19 13:47:31.164 26807-26807/com.example.bash1.sqlitediss e/androidruntime: fatal exception: main process: com.example.bash1.sqlitediss, pid: 26807 android.database.sqlite.sqliteexception: near "tablestock_table": syntax error (code 1): , while compiling: create tablestock_table (idnamedatereceivedexpirydate) 

my code function follows..

package com.example.bash1.sqlitediss; 

import android.content.contentvalues; import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper;

public class databasehelper extends sqliteopenhelper { public static final string database_stockdb = "stock.db";   public static final string database_stockdb = "stock.db"; public static final string table_name = "stock_table"; public static final string col_1 = "id"; public static final string col_2 = "name"; public static final string col_3 = "datereceived"; public static final string col_4 = "expirydate";  public databasehelper(context context) {     super(context, database_stockdb, null, 1);  }  @override public void oncreate(sqlitedatabase db) {     db.execsql("create table" + table_name + " (" + col_1 + col_2 + col_3 + col_4 + ")"); }  @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     db.execsql("drop table if exists table_name" + table_name);     oncreate(db); }  public boolean insertdata(string name, string datereceived, string expirydate){ sqlitedatabase db = this.getwritabledatabase();     contentvalues contentvalues = new contentvalues();     contentvalues.put(col_2, name);     contentvalues.put(col_3, datereceived);     contentvalues.put(col_4, expirydate);     long result = db.insert(table_name,null,contentvalues);     if (result == -1 )             return false;     else             return true;  }    } 

 db.execsql("create table "  + table_name + " (" + col_1 + col_2 + col_3 + col_4 + ")"); 

just add space after "create table "


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -