//DBHelper class
public static final String Query="CREATE TABLE "+UserConstruct.newUserinfo.TableName+" ("+UserConstruct.newUserinfo.UserName+" TEXT, "+UserConstruct.newUserinfo.Password+" TEXT,"+
UserConstruct.newUserinfo.FName+" TEXT, "+UserConstruct.newUserinfo.LName+" TEXT,"+UserConstruct.newUserinfo.ACode+" TEXT,"+UserConstruct.newUserinfo.AEmail+" TEXT);";
public DatabaseHelper(Context context)
{
super(context,DatabaseName,null,DatabaseVersion);
Log.e("Database operation","created or opened");
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(Query);
Log.e("Created","Table Created");
File f=new File("/data/data/com.example.future.buildingmonitoringsystem/databases/ptl2_DB.db");
FileInputStream fis=null;
FileOutputStream fos=null;
try
{
fis=new FileInputStream(f);
fos=new FileOutputStream("/mnt/sdcard/ptl2_DB.db");
while(true)
{
int i=fis.read();
if(i!=-1)
{fos.write(i);}
else
{break;}
}
fos.flush();
//code for insertion in main class
String UserName="admin"
Password = "password";
String FName="abc";
String LName="abc";
String ACode="1234";
String AEmail="sjn@gmail.com";
String TableName="htl_portal_user";
dbhelper=new DatabaseHelper(context);
sqlitedatabase=dbhelper.getWritableDatabase();
dbhelper.insert( UserName,Password,FName,LName,ACode,AEmail,sqlitedatabase);
Toast.makeText(getBaseContext(),"Data inserted",Toast.LENGTH_LONG).show();
dbhelper.close();
What I have tried:
I can see my db in device monitor, i can insert and access 1st row. I can insert second row also, but after the insertion i cant access db, app is hanging and stop.
And i export that db file and check the table, I can see that second row is a copy of first row(elements that i inserted first). Can any one provide a solution for this? My code for table creation and insertion are given below.