0

我正在尝试创建这个数据库,但它不起作用,我已经有了关于创建第一个表的答案,但是现在第二个表有一个错误日志:创建语法错误附近的 sqlexception。

公共类 DBAdapter {

private static final String DATABASE_NAME = "test";
private static final int DATABASE_VERSION = 3;

private static final String MENAGE = "table_MENAGE";



private static final String _id = "Numero_du_Questionnaire";
private static final String col_Code_district = "Code_district";
private static final String col_Region= "region";
private static final String col_Provence_prefecture  = "provence_prefecture";
private static final String col_Commune_Arrondissement  = "Commune_Arrondissement ";
private static final String col_N_district  = "Numero_district ";
private static final String col_N_M_district = "N_ménage_district ";
private static final String col_N_menage_logement  = "N_menage_logement ";
private static final String col_Adresse_menage = "Adresse_menage";
private static final String col_Nom_Enqueteur = "Nom_enqueteur";
private static final String col_code_enquêteur  = "code_enqueteur ";
private static final String col_Date_realisation_enquête  = "Date_réalisation_enquête ";
private static final String col_Nom_controleur  = "Nom_contrôleur ";
private static final String col_code_controleur  = "code_contrôleur ";
private static final String col_Date_controle  = "Date_contrôle ";
private static final String col_echantillon_principal  = "echantillon_principal";
private static final String col_Statut_enquêté  = "Statut_enquêté ";
private static final String col_Observations   = "Observations ";
private static final String col_Type_habitat   = "Type_habitat";
private static final String col_Statut_occupation   = "Statut_occupation ";
private static final String col_Nombre_ménages_habitant_logement   = "Nombre_ménages_habitant_logement ";
private static final String col_Nombre_pièces_occupes_ménage   = "Nombre_pièces_occupés_ménage ";
private static final String col_Mode_principal_approvisionnement_eau_potable    = "Mode_principal_approvisionnement_eau_potable  ";
private static final String col_Mode_principal_éclairage    = "Mode_principal_éclairage ";
private static final String col_Mode_principal_assainissement   = "Mode_principal_assainissement  ";
private static final String col_Disposition_local_cuisine   = "Disposition_local_cuisine ";
private static final String col_Disposition_local_WC   = "Disposition_local_WC ";
private static final String col_Disposition_salle_eau   = "Disposition_salle_eau  ";


private static final String Equipements_MENAGE = "table_Equipement_MENAGE ";


private static final String col_Radio= "Radio";
private static final String col_Télévision = "Télévision ";
private static final String col_Réfrigérateur= "Réfrigérateur";
private static final String col_Cuisinière= "Cuisinière";
private static final String col_Machine_laver = "Machine_laver ";
private static final String col_Parabole = "Parabole ";
private static final String col_Véhicule_moteur = "Véhicule_moteur ";
private static final String col_Internet= "Internet";
private static final String col_Téléphone_mobile = "Téléphone_mobile ";
private static final String col_Téléphone_fixe = "Téléphone_fixe ";
private static final String col_Autre= "Autre_preciser";


   private static final String DATABASE_CREATE = "CREATE TABLE " + MENAGE + "( " + _id    +" INTEGER PRIMARY KEY AUTOINCREMENT,"
        + col_Region +" TEXT,"+  col_Provence_prefecture +" TEXT,"
   + col_Commune_Arrondissement +" TEXT,"+ col_N_district +" INT,"
   + col_N_M_district +" INT,"+ col_N_menage_logement +" INT,"+ col_Adresse_menage +    "      INT," 
   + col_Nom_Enqueteur +" INT,"+ col_code_enquêteur +" INT,"+          col_Date_realisation_enquête +" INT,"
   + col_Nom_controleur +" INT,"+ col_code_controleur +" INT,"+ col_Date_controle +" INT,"
   + col_echantillon_principal +" INT,"+ col_Statut_enquêté +" INT,"+ col_Observations    +" INT,"
    + col_Type_habitat +" INT,"+ col_Statut_occupation +" INT,"+ col_Nombre_ménages_habitant_logement +" INT,"
   + col_Nombre_pièces_occupes_ménage +" INT,"+ col_Mode_principal_approvisionnement_eau_potable +" INT,"
  + col_Mode_principal_éclairage +" INT,"+ col_Mode_principal_assainissement +" INT,"
  + col_Disposition_local_cuisine +" INT,"
  + col_Disposition_salle_eau + " INT,"+ col_Disposition_local_WC +" INT" + ")"+"CREATE TABLE " + Equipements_MENAGE + "(" + col_Radio +" INT,"+ col_Télévision +" INT,"+ col_Réfrigérateur +" INT,"+ col_Cuisinière +" INT,"
 + col_Machine_laver +" INT,"+ col_Parabole +" INT," + col_Véhicule_moteur +" INT,"+ col_Internet +" INT,"+ col_Téléphone_mobile +" INT,"   

  + col_Téléphone_fixe +" INT,"+ col_Autre +" TEXT"+ ")";  
4

1 回答 1

0

您必须分别执行 SQL 才能创建两个表。

private static final String DATABASE_CREATE1, DATABASE_CREATE2

DATABASE_CREATE1 = "CREATE TABLE " + MENAGE .........

DATABASE_CREATE2 = "CREATE TABLE " + Equipements_MENAGE .........

在您的 DatabaseHelper 类中,您必须执行这些查询。

    public void onCreate(SQLiteDatabase db) throws SQLException {
        try {
            db.execSQL(ClassName.DATABASE_CREATE1);
            db.execSQL(ClassName.DATABASE_CREATE2);
        } catch (SQLException e) {
            Log.wtf("SQL ERROR", e.getMessage());
        }
    }
于 2013-10-28T23:58:53.567 回答