بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
اررو عجیب با sqllite (همراه با کد)(لطفا اگر بلد هستید کمک کنید، خیلی عجله ایی هست)
من وقتی از دیتابیس می خوام استفاده کنم و کویری بگریم این اررو رو می ده
(257) Open fd: 73, file: /data/data/com.ghaza.servicedehi/databases/main.db-journal
(257) Close fd: 73
و همین طور تکرار می شود. علت چی هست؟
public class book_database_handler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "main.db";
private static final String TABLE_FAV = "main";
private static Context ctx;
public book_database_handler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
ctx = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
String destPath = "/data/data/" + ctx.getPackageName()
+ "/databases";
String destPathfile = "/data/data/" + ctx.getPackageName()
+ "/databases/" + DATABASE_NAME;
File f_path = new File(destPath);
File f_pathfile = new File(destPathfile);
if (!f_path.exists()) {
f_path.mkdirs();
f_path.createNewFile();
CopyDB(ctx.getAssets().open(DATABASE_NAME),
new FileOutputStream(destPath + "/" + DATABASE_NAME));
}
if (!f_pathfile.exists()) {
f_pathfile.createNewFile();
CopyDB(ctx.getAssets().open(DATABASE_NAME),
new FileOutputStream(destPath + "/" + DATABASE_NAME));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
// db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAV);
// Create tables again
// onCreate(db);
}
public void add_book(int year, int month, int day, int total_oil,
int use_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("year", year);
values.put("month",( month+1));
values.put("day", day);
values.put("total_oil", total_oil);
values.put("use_oil", use_oil);
// Inserting Row
db.insert(TABLE_FAV, null, values);
db.close(); // Closing database connection
}
public book_item get_book(int year, int month, int day) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_FAV, new String[] {
"year", "month", "day", "total_oil", "use_oil"
}, " year " + " =? " + " AND " + " month " + " =? " + " AND " + " day "
+ " =? ",
new String[] { String.valueOf(year), String.valueOf(month + 1),
String.valueOf(day) }, null, null, null, null);
book_item book = null;
if (cursor != null) {
cursor.moveToFirst();
try {
book = new book_item(cursor.getString(0),
cursor.getString(1), cursor.getString(2),
cursor.getString(3), cursor.getString(4));
db.close();
return book;
} catch (Exception i) {
book = new book_item("null", "0", "0");
db.close();
return book;
}
}
db.close();
return book;
}
public int update_book(int year, int month, int day, int total_oil,
int use_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("year", year);
values.put("month", (month+1));
values.put("day", day);
values.put("total_oil", total_oil);
values.put("use_oil", use_oil);
int i = db.update(TABLE_FAV, values, "year" + " = ? " + " AND month "
+ " = ? " + " AND day " + " = ? ", new String[] { year + "",
(month+1) + "", day + "" });
db.close();
return i;
}
public int update_book_just_total_oil(int year, int month, int day,
int total_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("total_oil", total_oil);
int i = db.update(TABLE_FAV, values, "year" + " = ?" + " AND month "
+ " = ? " + " AND day " + " = ? ", new String[] { year + "",
(month+1) + "", day + "" });
db.close();
return i;
}
public void delete_book(int fk_id, String kind) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_FAV, " fk_id " + " = ?" + " AND kind " + " = ? ",
new String[] { String.valueOf(fk_id), kind });
db.close();
}
public int get_book_Count(String kind) {
String countQuery = "SELECT * FROM " + TABLE_FAV + " where kind = '"
+ kind + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int num = cursor.getCount();
cursor.close();
db.close();
return num;
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
// ---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
}
0
0
کسی بلد نیست؟ (11 سال پیش)
0
0
این کد من هست در یک کلاس گزاشتم.
public class book_database_handler extends SQLiteOpenHelper {
private static final int DATABASE_VERSI
private static final String DATABASE_NAME = "main.db";
private static final String TABLE_FAV = "main";
private static Context ctx;
public book_database_handler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
ctx = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
String destPath = "/data/data/" + ctx.getPackageName()
+ "/databases";
String destPathfile = "/data/data/" + ctx.getPackageName()
+ "/databases/" + DATABASE_NAME;
File f_path = new File(destPath);
File f_pathfile = new File(destPathfile);
if (!f_path.exists()) {
f_path.mkdirs();
f_path.createNewFile();
CopyDB(ctx.getAssets().open(DATABASE_NAME),
new FileOutputStream(destPath + "/" + DATABASE_NAME));
}
if (!f_pathfile.exists()) {
f_pathfile.createNewFile();
CopyDB(ctx.getAssets().open(DATABASE_NAME),
new FileOutputStream(destPath + "/" + DATABASE_NAME));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
لینک Drop older table if existed
لینک db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAV);
لینک Create tables again
لینک onCreate(db);
}
public void add_book(int year, int month, int day, int total_oil,
int use_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("year", year);
values.put("month",( month+1));
values.put("day", day);
values.put("total_oil", total_oil);
values.put("use_oil", use_oil);
لینک Inserting Row
db.insert(TABLE_FAV, null, values);
db.close(); لینک Closing database connection
}
public book_item get_book(int year, int month, int day) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_FAV, new String[] {
"year", "month", "day", "total_oil", "use_oil"
}, " year " + " =? " + " AND " + " month " + " =? " + " AND " + " day "
+ " =? ",
new String[] { String.valueOf(year), String.valueOf(month + 1),
String.valueOf(day) }, null, null, null, null);
book_item book = null;
if (cursor != null) {
cursor.moveToFirst();
try {
book = new book_item(cursor.getString(0),
cursor.getString(1), cursor.getString(2),
cursor.getString(3), cursor.getString(4));
db.close();
return book;
} catch (Exception i) {
book = new book_item("null", "0", "0");
db.close();
return book;
}
}
db.close();
return book;
}
public int update_book(int year, int month, int day, int total_oil,
int use_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("year", year);
values.put("month", (month+1));
values.put("day", day);
values.put("total_oil", total_oil);
values.put("use_oil", use_oil);
int i = db.update(TABLE_FAV, values, "year" + " = ? " + " AND month "
+ " = ? " + " AND day " + " = ? ", new String[] { year + "",
(month+1) + "", day + "" });
db.close();
return i;
}
public int update_book_just_total_oil(int year, int month, int day,
int total_oil) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("total_oil", total_oil);
int i = db.update(TABLE_FAV, values, "year" + " = ?" + " AND month "
+ " = ? " + " AND day " + " = ? ", new String[] { year + "",
(month+1) + "", day + "" });
db.close();
return i;
}
public void delete_book(int fk_id, String kind) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_FAV, " fk_id " + " = ?" + " AND kind " + " = ? ",
new String[] { String.valueOf(fk_id), kind });
db.close();
}
public int get_book_Count(String kind) {
String countQuery = "SELECT * FROM " + TABLE_FAV + " where kind = '"
+ kind + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int num = cursor.getCount();
cursor.close();
db.close();
return num;
}
public void CopyDB(InputStream inputStream, OutputStream outputStream)
throws IOException {
لینک ---copy 1K bytes at a time---
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
}
}
(11 سال پیش)
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .