dimanche 19 avril 2015

SQLite Database creating problems with my code

First time ever using SQLite, I have been using an online tutorial which show me how to create a database and a table. My table should have 3 columns of TEXT type which are name, email and password. Unfortunately, it doesn't seem to work, and I really don't know why, i think it's due to this error

" Caused by: android.database.sqlite.SQLiteException: near "CREATE_TABLE": syntax error (code 1): , while compiling: CREATE_TABLE Registered_Info(UserName TEXT,Password TEXT,Email TEXT);"

Here is my code.

package com.example.wolfe_000.final_final_zeno;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

* Created by wolfe_000 on 19/04/2015.
public class DatabaseOperations extends SQLiteOpenHelper {

public static int database_version = 1;
public String CREATE_QUERY = "CREATE_TABLE "+ TableData.TableInfo.TABLE_NAME+"("+ TableData.TableInfo.USER_NAME+" TEXT,"+ TableData.TableInfo.USER_PASS+" TEXT,"+TableData.TableInfo.USER_EMAIL+" TEXT);";

public DatabaseOperations(Context context){
super(context, TableData.TableInfo.DATABASE_NAME,null,database_version);
Log.d("Database Operations", "Database Created");

public void onCreate(SQLiteDatabase sdb){
Log.d("Database Operations", "Database Created");

public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {


public void putInformation(DatabaseOperations dop, String name, String pass, String email){
SQLiteDatabase SQ = dop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_NAME, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
cv.put(TableData.TableInfo.USER_EMAIL, email);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME,null, cv);
Log.d("Database Operations", "One Raw Inserted");


The error occurs when I click my SignUp button using this code:

public void SignUpOnClick(View view ){
user_name = USER_NAME.getText().toString();
user_email = USER_EMAIL.getText().toString();
user_pass = USER_PASS.getText().toString();

DatabaseOperations DB = new DatabaseOperations(ctx);
DB.putInformation(DB, user_name, user_email, user_pass);
Toast.makeText(getBaseContext(), "Successfully Registered", Toast.LENGTH_LONG).show();

Aucun commentaire:

Enregistrer un commentaire