2014-10-30 4 views
0

У меня проблема при размещении данных в SQLite, я приближаюсь к «порядку»: синтаксическая ошибка (код 1): при компиляции: CREATE TABLE position_arret (id INTEGER PRIMARY KEY, закажите TEXT , Libelle TEXT, PosX ТЕКСТ, ТЕКСТ Пози)Ошибка при создании базы данных в SQLite

Я следующие классы

Положение станции класса в

public class Position_Station { 

     //variables 
     int _id; 
     String _PosX; 
     String _PosY; 
     String _Order; 
     String _Libelle; 


     // Empty constructor 
     public Position_Station(){} 
     // constructor 
     public Position_Station(int id,String order, String libelle, String posx, String posy){ 
      this._id = id; 
      this._Libelle=libelle; 
      this._Order=order; 
      this._PosX = posx; 
      this._PosY=posy; 

     } 

     // constructor 
     public Position_Station(String order, String libelle, String posx, String posy){ 
      this._Libelle=libelle; 
      this._Order=order; 
      this._PosX = posx; 
      this._PosY=posy; 
     } 


     // getting ID SQLITE///////////////////////// 
     public int getID(){ 
      return this._id; 
     } 

        // setting ID SQLITE 
        public void setID(int id){ 
         this._id = id; 
        } 


     // getting Libelle////////////////////////////// 
     public String getLibelle(){ 
      return this._Libelle; 
     } 

        // setting Libelle 
        public void setLibelle(String libelle){ 
         this._Libelle = libelle; 
        } 


     // getting Order////////////////////////////// 
     public String getOrder(){ 
      return this._Order; 
     } 

        // setting Order 
        public void setOrder(String order){ 
         this._Order = order; 
        }     


     // getting PosX////////////////////////////// 
     public String getPosX(){ 
      return this._PosX; 
     } 

        // setting PosX 
        public void setPosX(String posx){ 
         this._PosX = posx; 
        } 

     // getting PosY/////////////////////////// 
     public String getPosY(){ 
      return this._PosY; 
     } 

        // setting PosY 
        public void setPosY(String posy){ 
         this._PosY = posy; 
        } 
    } 

мой DatabaseHandler Класс, как

public class DatabaseHandlerStation extends SQLiteOpenHelper { 

    // Database Version 
    private static final int DATABASE_VERSION = 2; 

    // Database Name 
    private static final String DATABASE_NAME = "POSITIONSSTATIONMANAGER"; 

    // Contacts table name 
    private static final String TABLE_POSITIONS = "position_arret"; 

    // Table Columns names 
    private static final String KEY_ID = "id"; 
    private static final String KEY_LIBELLE = "libelle"; 
    private static final String KEY_ORDER="order"; 
    private static final String KEY_POSX = "posx"; 
    private static final String KEY_POSY="posy"; 

    public DatabaseHandlerStation(Context context) { 
     super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    } 

    // Creating Tables 
    @Override 
    public void onCreate(SQLiteDatabase db) { 

     String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_POSITIONS + "(" 
       + KEY_ID + " INTEGER PRIMARY KEY," 
       + KEY_ORDER + " TEXT," 
       + KEY_LIBELLE + " TEXT," 
       + KEY_POSX + " TEXT," 
       + KEY_POSY + " TEXT" +")"; 
     db.execSQL(CREATE_CONTACTS_TABLE); 
    } 

    // Upgrading database 
    @Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
     // Drop older table if existed 
     db.execSQL("DROP TABLE IF EXISTS " + TABLE_POSITIONS); 

     // Create tables again 
     onCreate(db); 
    } 

    /** 
    * All CRUD(Create, Read, Update, Delete) Operations 
    */ 
    //delete all rows in table 
    public void deleteAll() 
    { 
     SQLiteDatabase db = this.getWritableDatabase(); 
     db.delete(TABLE_POSITIONS,null,null); 
     // db.execSQL("DROP TABLE IF EXISTS " + TABLE_POSITIONS); 
     // db.execSQL("TRUNCATE TABLE " + TABLE_POSITIONS); 
     db.close(); 
    } 

    // Adding new position 
    void addPosition(Position_Station p_station) { 
     SQLiteDatabase db = this.getWritableDatabase(); 

     ContentValues values = new ContentValues(); 
     values.put(KEY_ORDER, p_station.getOrder()); 
     values.put(KEY_LIBELLE, p_station.getLibelle()); 
     values.put(KEY_POSX, p_station.getPosX()); // Laltitude Pos x 
     values.put(KEY_POSY, p_station.getPosY()); // Longitude Pos y 


     // Inserting Row 
     db.insert(TABLE_POSITIONS, null, values); 
     db.close(); // Closing database connection 
    } 



    // Getting All Positions 
    public List<Position_Station> getAllPositions() { 
     List<Position_Station> positionList = new ArrayList<Position_Station>(); 
     // Select All Query 
     String selectQuery = "SELECT * FROM " + TABLE_POSITIONS; 

     SQLiteDatabase db = this.getWritableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery, null); 

     // looping through all rows and adding to list 
     if (cursor.moveToFirst()) { 
      do { 
       Position_Station pos_station = new Position_Station(); 
       pos_station.setID(Integer.parseInt(cursor.getString(0))); 
       pos_station.setOrder(cursor.getString(1)); 
       pos_station.setLibelle(cursor.getString(2)); 
       pos_station.setPosX(cursor.getString(3)); 
       pos_station.setPosX(cursor.getString(4)); 
       // Adding contact to list 
       positionList.add(pos_station); 
      } while (cursor.moveToNext()); 
     } 
     cursor.close(); 
     db.close(); 
     // return contact list 
     return positionList; 
    } 

    // Updating single position 
    public int updatePosition_Station(Position_Station position) { 
     SQLiteDatabase db = this.getWritableDatabase(); 

     ContentValues values = new ContentValues(); 
     values.put(KEY_ORDER, position.getOrder()); 
     values.put(KEY_LIBELLE, position.getLibelle()); 
     values.put(KEY_POSX, position.getPosX()); 
     values.put(KEY_POSY, position.getPosY()); 

     // updating row 
     return db.update(TABLE_POSITIONS, values, KEY_ID + " = ?", 
       new String[] { String.valueOf(position.getID()) }); 
    } 

    // Deleting single position 
    public void deletePosition(Position_Station position) { 
     SQLiteDatabase db = this.getWritableDatabase(); 
     db.delete(TABLE_POSITIONS, KEY_ID + " = ?", 
       new String[] { String.valueOf(position.getID()) }); 
     db.close(); 
    } 

    // Getting Positions Count 
    public int getPositionsCount() { 
     String countQuery = "SELECT * FROM " + TABLE_POSITIONS; 
     int i; 
     SQLiteDatabase db = this.getReadableDatabase(); 
     Cursor cursor = db.rawQuery(countQuery, null); 
     i=cursor.getCount(); 
     cursor.close(); 
     // return count 
     return i; 
    } 



    // Getting all posx and posy 
    public ArrayList<LatLng> getAllPos() { 
     ArrayList<LatLng> coordList = new ArrayList<LatLng>(); 
     // Select All Query 
     String selectQuery = "SELECT * FROM " + TABLE_POSITIONS; 

     SQLiteDatabase db = this.getWritableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery, null); 

     // looping through all rows and adding to list 
     if (cursor.moveToFirst()) { 
      do { 
       // Position position = new Position(); 
       // position.setPosX(cursor.getString(1)); 
       // position.setPosY(cursor.getString(2)); 
       // Adding position to list 
       coordList.add(new LatLng(Double.parseDouble(cursor.getString(3)) 
         ,Double.parseDouble(cursor.getString(4)))); 
      } while (cursor.moveToNext()); 
     } 
     cursor.close(); 
     db.close(); 
     // return contact list 
     return coordList; 
    } 

    // Getting all posx, posy, and information 
    public ArrayList<Position_Station> getAllPos_info() { 
     ArrayList<Position_Station> coordList = new ArrayList<Position_Station>(); 
     // Select All Query 
     String selectQuery = "SELECT * FROM " + TABLE_POSITIONS; 

     SQLiteDatabase db = this.getWritableDatabase(); 
     Cursor cursor = db.rawQuery(selectQuery, null); 

     // looping through all rows and adding to list 
     if (cursor.moveToFirst()) { 
      do { 
       Position_Station pos_station = new Position_Station(); 
       pos_station.setOrder(cursor.getString(1)); 
       pos_station.setLibelle(cursor.getString(2)); 
       pos_station.setPosX(cursor.getString(3)); 
       pos_station.setPosY(cursor.getString(4)); 
       // Adding position to list 
       coordList.add(pos_station); 
      } while (cursor.moveToNext()); 
     } 
     cursor.close(); 
     db.close(); 
     // return contact list 
     return coordList; 
    } 
} 

Моего MainActivity, как, когда я хочу, чтобы поместить данные в базе данных

DatabaseHandlerStation db_pos_station= new DatabaseHandlerStation(this); 

JSONArray jsonArret = new JSONArray(Data); 
         for(int i=0;i < jsonArret.length();i++) { 
          JSONObject jsonobj = jsonArret.getJSONObject(i); 
          String order=jsonobj.getString(TAG_ORDER); 
          String libel=jsonobj.getString(TAG_LIBELLE); 
          String posx=jsonobj.getString(TAG_POSX_STATION); 
          String posy=jsonobj.getString(TAG_POSY_STATION); 
          db_pos_station.addPosition(new Position_Station(order,libel,posx,posy)); 

Благодарность

+0

заказ сохранившийся слово ..... –

ответ

1

порядок является зарезервированным словом SQL, переименовывать запись, и она будет работать нормально

+0

thakns это сделано –

1

order является SQL ключевого слова. Переименуйте столбец или укажите его в "double quotes".

Смежные вопросы