【发布时间】:2016-09-30 05:34:37
【问题描述】:
我的数据文件夹在设备监视器中是空的。当我将 db 放入内部存储器时,我可以看到在 sdcard0 中,我可以访问该文件但不能写入超过一行。 〜我是android的新手〜。这是我的代码,
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();
【问题讨论】:
-
不能写超过 1 行?你的方法是什么?您尝试执行的代码在哪里?这很快就会被否决。
-
你的设备root了吗?
-
设备未植根。
-
请将您的代码发布到您在数据库中插入数据的位置
标签: android sqlite android-studio file-io