Hi everybody!
I have made a app and I am using a Sqlite app. At first it runs properly but now when I am programming some issues in the app and I have to use a sqlite instruction the app breaks. For this reason I have returned to the first steps with a sqlite database, however the app continues breaking .
I have check the code so many times but i dont know what happend...i cant undestand nothing
***DATABASE CODE***
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
public class accesobd extends SQLiteOpenHelper {
public accesobd(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE PERSONAS (_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "dni INTEGER, nie INTEGER, nombre TEXT, apellido text, ano INTEGER);"
);
db.execSQL("CREATE TABLE PERSONAS1 (_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "registro INTEGER, nregistros INTEGER, dnin INTEGER, nombre TEXT, apellido text, fecha INTEGER, nacionalidad TEXT, domicilio TEXT, estado TEXT, ordinal INTEGER);"
);
}
@override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// db.execSQL("DROP TABLE IF EXISTS PERSONA");
}
public boolean insertarRegistro (String dni, String nie, String nombre, String apellido, String ano) {
SQLiteDatabase sql = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("dni", dni);
cv.put("nie", nie);
cv.put("nombre", nombre);
cv.put("apellido", apellido);
cv.put("ano", ano);
if (sql.insert("PERSONAS", null, cv) != -1) return true;
else return false;
}
public String [] leerRegistro (String dni) {
SQLiteDatabase sql = this.getReadableDatabase();
Cursor c = sql.query(true, "PERSONAS", new String[] {"nombre", "apellido" ,"ano"},"dni='"+dni+"'",null,null,null,null,null);
String [] aux = {"0", "0" ,"0"};
if (c.moveToFirst()) {
//Recorremos el cursor hasta que no haya más registros
do {
aux[0]= c.getString(0); //nombre
aux[1] = c.getString(1); //apellido
aux[2]= c.getString(2); //ano
} while(c.moveToNext());
}
return aux;
}
public boolean insertarRegistrobd1 (String registro, String nregistro, String dnin, String nombre, String apellido, String fecha,
String nacional, String domicilio, String estado, String ordinal) {
SQLiteDatabase sql = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("registro", registro);
cv.put("nregistro", nregistro);
cv.put("dnin", dnin);
cv.put("nombre", nombre);
cv.put("apellido", apellido);
cv.put("fecha", fecha);
cv.put("nacional", nacional);
cv.put("domicilio", domicilio);
cv.put("estado", estado);
cv.put("ordinal", ordinal);
if (sql.insert("PERSONAS1", null, cv) != -1) return true;
else return false;
}
public String [] leerRegistro1bd1 (String nombre) {
SQLiteDatabase sql = this.getReadableDatabase();
Cursor c = sql.query(true, "PERSONAS1", new String[] {"registro","nregistro", "apellido" ,
"fecha", "nacional", "domicilio", "estado", "ordinal, dnin"},
"nombre='"+nombre+"'",null,null,null,null,null);
String [] aux = {"0", "0" ,"0","0", "0" ,"0","0", "0", "0" };
StringBuilder aux = new StringBuilder();
if (c.moveToFirst()) {
do {
aux[0]= c.getString(0); //registro
aux[1] = c.getString(1); //nregistro
aux[2]= c.getString(3); //apellido
aux[3] = c.getString(4); //fecha
aux[4]= c.getString(5); //nacional
aux[5]= c.getString(6); //domicilio
aux[6] = c.getString(7); //estado
aux[7]= c.getString(8); //ordinal
aux[8]= c.getString(8); //dnin
} while(c.moveToNext());
return aux;
}
///MAIN ACTIVITY
public class Consulta1 extends Activity implements OnClickListener {
public accesobd bd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.consulta1);
bd = new accesobd(this, "BBDD_clase", null, 1);
boolean resultado = bd.insertarRegistro("0", "0","0","0","0");
resultado = bd.insertarRegistrobd1("0", "0","0","0","0", "0", "0","0","0","0");
}
The most strange thing is that the app breaks (I have tested it in debug mode) only with the instruction bd.insertarRegistrobd1, and with the instruction bd.insertarRegistro it runs properly.
Thanks a lot
I have made a app and I am using a Sqlite app. At first it runs properly but now when I am programming some issues in the app and I have to use a sqlite instruction the app breaks. For this reason I have returned to the first steps with a sqlite database, however the app continues breaking .
I have check the code so many times but i dont know what happend...i cant undestand nothing
***DATABASE CODE***
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;
public class accesobd extends SQLiteOpenHelper {
public accesobd(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE PERSONAS (_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "dni INTEGER, nie INTEGER, nombre TEXT, apellido text, ano INTEGER);"
);
db.execSQL("CREATE TABLE PERSONAS1 (_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "registro INTEGER, nregistros INTEGER, dnin INTEGER, nombre TEXT, apellido text, fecha INTEGER, nacionalidad TEXT, domicilio TEXT, estado TEXT, ordinal INTEGER);"
);
}
@override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// db.execSQL("DROP TABLE IF EXISTS PERSONA");
}
public boolean insertarRegistro (String dni, String nie, String nombre, String apellido, String ano) {
SQLiteDatabase sql = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("dni", dni);
cv.put("nie", nie);
cv.put("nombre", nombre);
cv.put("apellido", apellido);
cv.put("ano", ano);
if (sql.insert("PERSONAS", null, cv) != -1) return true;
else return false;
}
public String [] leerRegistro (String dni) {
SQLiteDatabase sql = this.getReadableDatabase();
Cursor c = sql.query(true, "PERSONAS", new String[] {"nombre", "apellido" ,"ano"},"dni='"+dni+"'",null,null,null,null,null);
String [] aux = {"0", "0" ,"0"};
if (c.moveToFirst()) {
//Recorremos el cursor hasta que no haya más registros
do {
aux[0]= c.getString(0); //nombre
aux[1] = c.getString(1); //apellido
aux[2]= c.getString(2); //ano
} while(c.moveToNext());
}
return aux;
}
public boolean insertarRegistrobd1 (String registro, String nregistro, String dnin, String nombre, String apellido, String fecha,
String nacional, String domicilio, String estado, String ordinal) {
SQLiteDatabase sql = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("registro", registro);
cv.put("nregistro", nregistro);
cv.put("dnin", dnin);
cv.put("nombre", nombre);
cv.put("apellido", apellido);
cv.put("fecha", fecha);
cv.put("nacional", nacional);
cv.put("domicilio", domicilio);
cv.put("estado", estado);
cv.put("ordinal", ordinal);
if (sql.insert("PERSONAS1", null, cv) != -1) return true;
else return false;
}
public String [] leerRegistro1bd1 (String nombre) {
SQLiteDatabase sql = this.getReadableDatabase();
Cursor c = sql.query(true, "PERSONAS1", new String[] {"registro","nregistro", "apellido" ,
"fecha", "nacional", "domicilio", "estado", "ordinal, dnin"},
"nombre='"+nombre+"'",null,null,null,null,null);
String [] aux = {"0", "0" ,"0","0", "0" ,"0","0", "0", "0" };
StringBuilder aux = new StringBuilder();
if (c.moveToFirst()) {
do {
aux[0]= c.getString(0); //registro
aux[1] = c.getString(1); //nregistro
aux[2]= c.getString(3); //apellido
aux[3] = c.getString(4); //fecha
aux[4]= c.getString(5); //nacional
aux[5]= c.getString(6); //domicilio
aux[6] = c.getString(7); //estado
aux[7]= c.getString(8); //ordinal
aux[8]= c.getString(8); //dnin
} while(c.moveToNext());
return aux;
}
///MAIN ACTIVITY
public class Consulta1 extends Activity implements OnClickListener {
public accesobd bd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.consulta1);
bd = new accesobd(this, "BBDD_clase", null, 1);
boolean resultado = bd.insertarRegistro("0", "0","0","0","0");
resultado = bd.insertarRegistrobd1("0", "0","0","0","0", "0", "0","0","0","0");
}
The most strange thing is that the app breaks (I have tested it in debug mode) only with the instruction bd.insertarRegistrobd1, and with the instruction bd.insertarRegistro it runs properly.
Thanks a lot