IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Problème de réquête SQLite Android Studio


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2020
    Messages
    15
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Janvier 2020
    Messages : 15
    Par défaut Problème de réquête SQLite Android Studio
    Bonjour,
    Je suis débutant en android et je développe une appli en insérant des objets dans une base de données avec SQLite.
    J'ai trois attributs qui ne refusent l'insertion dans la base de données pour un problème de type, si je les enlève la réquête marche très bien.
    voici mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    private String[] images;
    private Long date; // Que je convertirai en date plus tard
    private int prix;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    public class AnnonceDbOpener extends SQLiteOpenHelper {
     
        public static  int DATABASE_VERSION = 1;
        public static final String DATABASE_NAME = "annonces.db";
     
        private static final String SQL_CREATE_ENTRIES =
                "CREATE TABLE " + AnnoceContract.FeedEntry.TABLE_NAME + " (" +
                        AnnoceContract.FeedEntry._ID + " INTEGER PRIMARY KEY autoincrement," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_ID + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_TITRE + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_DESCRIPTION + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_PRIX + "TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_PSEUDO + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_EMAIL + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_TELEPHONE + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_VILLE + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_CODE_POSTAL + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_IMAGES + " TEXT," +
                        AnnoceContract.FeedEntry.COLUMN_NAME_DATE + " TEXT)";
     
        private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + AnnoceContract.FeedEntry.TABLE_NAME;
     
        public AnnonceDbOpener(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }
     
     
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(SQL_CREATE_ENTRIES);
        }
     
        public void setDatabaseVersion(int version){
            this.DATABASE_VERSION = version;
        }
     
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
           db.execSQL(SQL_DELETE_ENTRIES);
            onCreate(db);
            //setDatabaseVersion(newVersion);
        }
     
        public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            onUpgrade(db, oldVersion, newVersion);
        }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     
    public class AnnonceDb {
     
        private AnnonceDbOpener annonceDbOpener;
     
        public AnnonceDb(Context context)
        {
            annonceDbOpener = new AnnonceDbOpener(context);
        }
     
        public long ajouter(Annonce annonce)
        {
            SQLiteDatabase db = annonceDbOpener.getWritableDatabase();
            ContentValues values = new ContentValues();
            //int price = Integer.parseInt(String.valueOf(AnnoceContract.FeedEntry.COLUMN_NAME_PRIX));
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_ID , annonce.getId());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_TITRE , annonce.getTitre());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_DESCRIPTION , annonce.getDescription());
           // values.put( AnnoceContract.FeedEntry.COLUMN_NAME_PRIX, String.valueOf(annonce.getPrix()));
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_PSEUDO , annonce.getPseudo());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_EMAIL , annonce.getEmailContact());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_TELEPHONE , annonce.getTelContact());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_VILLE , annonce.getVille());
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_CODE_POSTAL , annonce.getCp());
            //values.put(String.valueOf(AnnoceContract.FeedEntry.COLUMN_NAME_IMAGES).toString(), annonce.getImages()[0]);
            values.put( AnnoceContract.FeedEntry.COLUMN_NAME_DATE, String.valueOf(annonce.getDate()));
            long res = db.insert(AnnoceContract.FeedEntry.TABLE_NAME, null, values);
            //Log.i("vvv", typeof(AnnoceContract.FeedEntry.COLUMN_NAME_PRIX));
            //db.close();
            return res;
        }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    public final class AnnoceContract {
        // To prevent someone from accidentally instantiating the contract class,
        // make the constructor private.
        private AnnoceContract() {}
     
        /* Inner class that defines the table contents */
        public static class FeedEntry implements BaseColumns {
            public static final String TABLE_NAME = "annonce";
            public static final String COLUMN_NAME_ID = "id";
            public static final String COLUMN_NAME_TITRE = "titre";
            public static final String COLUMN_NAME_DESCRIPTION = "description";
            public static final String COLUMN_NAME_PRIX = "prix";
            public static final String COLUMN_NAME_PSEUDO = "pseudo";
            public static final String COLUMN_NAME_EMAIL = "emailContact";
            public static final String COLUMN_NAME_TELEPHONE = "telContact";
            public static final String COLUMN_NAME_VILLE = "ville";
            public static final String COLUMN_NAME_CODE_POSTAL = "codePostal";
            public static final String[] COLUMN_NAME_IMAGES = {};
            public static final String COLUMN_NAME_DATE = "date";
        }
    }
    J'aurais besoin d'aide

  2. #2
    Membre très actif Avatar de theocbr
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2019
    Messages
    206
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2019
    Messages : 206
    Par défaut
    Montre nous la structure de ta table stp

Discussions similaires

  1. Recherche "aléatoire dans SQLite Android Studio
    Par carus dans le forum Android Studio
    Réponses: 5
    Dernier message: 10/06/2017, 00h03
  2. problème d'exécution sur Android Studio
    Par drsbmm dans le forum Android Studio
    Réponses: 3
    Dernier message: 09/05/2017, 14h48
  3. problème d'exécution en Android studio
    Par moumenach dans le forum Android Studio
    Réponses: 0
    Dernier message: 24/06/2016, 06h37
  4. Réponses: 0
    Dernier message: 19/06/2015, 16h29
  5. Problème Create table SQLIte Android
    Par abradax dans le forum Android
    Réponses: 2
    Dernier message: 06/05/2013, 11h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo