import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper{
public final String path = "data/data/ir.dictionary/databases/";
public final String Name = "ENFADB";
public SQLiteDatabase mydb;
private final Context mycontext;
public Database(Context context) {
super(context, "ENFADB", null, 1);
mycontext = context;
}
@Override
public void onCreate(SQLiteDatabase arg0) {
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public void useable() {
boolean checkdb = checkdb();
if (checkdb) {
} else {
this.getReadableDatabase();
try {
copydatabase();
}
catch (IOException e) {
}
}
}
public void open() {
mydb = SQLiteDatabase.openDatabase(path + Name, null, SQLiteDatabase.OPEN_READWRITE);
}
@Override
public void close() {
mydb.close();
}
public boolean checkdb() {
SQLiteDatabase db = null;
try {
db = SQLiteDatabase.openDatabase(path + Name, null, SQLiteDatabase.OPEN_READONLY);
}
catch (SQLException e) {
}
retu db != null ? true : false;
}
public void copydatabase() throws IOException {
OutputStream myOutput = new FileOutputStream(path + Name);
byte[] buffer = new byte[1024];
int lenght;
InputStream myInput = mycontext.getAssets().open(Name);
while ((lenght = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, lenght);
}
myInput.close();
myOutput.flush();
myOutput.close();
}
public String showresult(int row , int field , String table){
Cursor cursor = mydb.rawQuery("SELECT * FROM " + table, null);
cursor.moveToPosition(row);
String str = cursor.getString(field);
retu "str";
}
}
- - , .
.
روید باکس...
ما را در سایت روید باکس دنبال می کنید
برچسب : نویسنده : کاوه محمدزادگان roid بازدید : 167 تاريخ : شنبه 26 تير 1395 ساعت: 0:37