Hai,
How can i solve this error. I'm new in android apps. please help.
my code is like
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
public static final String KEY_ROWID = "_id";
public static final String KEY_USERNAME = "username";
public static final String KEY_PWDL = "pwdl";
public static final String KEY_PWDD = "pwdd";
public static final String KEY_ROLE = "role";
private static final String TAG = "DBAdap";
private static final String DATABASE_NAME = "Paydb";
private static final String DATABASE_TABLE = "table1";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_CREATE = "create table table1 (_id integer primary key, " + "username text not null,"+ " pwdl text not null, "
+ "pwdd text not null,"+ "role integer not null);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
public DBAdapter(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
public static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS table1");
onCreate(db);
}
}
public DBAdapter open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
public void close()
{
DBHelper.close();
}
public long insertUser(Integer id, String name, String pwdl,String pwdd,Integer role)
{
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_ROWID, id);
initialValues.put(KEY_USERNAME, name);
initialValues.put(KEY_PWDL, pwdl);
initialValues.put(KEY_PWDD, pwdd);
initialValues.put(KEY_ROLE, role);
return db.insert(DATABASE_TABLE, null, initialValues);
}
public Cursor getUser1(Integer Role) throws SQLException
{
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_USERNAME, KEY_PWDL, KEY_PWDD,KEY_ROLE }, KEY_ROLE +"="+ Role, null, null, null, null, null);
if (mCursor != null)
{
mCursor.moveToFirst();
}
return mCursor;
}
public Cursor getUser2(String user) throws SQLException
{
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_USERNAME, KEY_PWDL, KEY_PWDD,KEY_ROLE }, KEY_USERNAME +"=" + user, null, null, null, null, null);
if (mCursor != null)
{
mCursor.moveToFirst();
}
return mCursor;
}
}
regards
vani