- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
错误这一行:
mDataBase = SQLiteDatabase.openDatabase(dbPath, "123", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
error : net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master
import android.content.Context;
import android.database.SQLException;
//import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import net.sqlcipher.database.SQLiteDatabase.CursorFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.File;
import net.sqlcipher.database.SQLiteDatabase;
import android.app.Activity;
import android.os.Bundle;
public class DatabaseHelper extends SQLiteOpenHelper {
private static String TAG = DatabaseHelper.class.getName();
private static String DB_PATH = "";
private static String DB_NAME = "ec.db";// Database name
private SQLiteDatabase mDataBase;
private final Context mContext;
File databaseFile=null;
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, 1);
DB_PATH = context.getApplicationInfo().dataDir + "/databases/";
this.mContext = context;
SQLiteDatabase.loadLibs(context);
File databaseFile = context.getDatabasePath(DB_NAME);
databaseFile.mkdirs();
}
public void createDataBase() throws IOException {
// If database not exists copy it from the assets
boolean mDataBaseExist = checkDataBase();
if (!mDataBaseExist) {
this.getWritableDatabase("123");
this.close();
try {
// Copy the database from assests
copyDataBase();
Log.e(TAG, "createDatabase database created");
} catch (IOException mIOException) {
throw new Error(mIOException.toString() + " : " + DB_PATH
+ DB_NAME);// "ErrorCopyingDataBase"
}
}
}
private boolean checkDataBase() {
File dbFile = new File(DB_PATH + DB_NAME);
return dbFile.exists();
}
// Copy the database from assets
private void copyDataBase() throws IOException {
InputStream mInput = mContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream mOutput = new FileOutputStream(outFileName);
byte[] mBuffer = new byte[4096];
int mLength;
while ((mLength = mInput.read(mBuffer)) > 0) {
mOutput.write(mBuffer, 0, mLength);
}
mOutput.flush();
mOutput.close();
mInput.close();
}
// Open the database, so we can query it
public boolean openDataBase() throws SQLException {
String mPath = DB_PATH + DB_NAME;
//File dbFile = new File(DB_PATH + DB_NAME);
//File databaseFile = mContext.getDatabasePath(DB_NAME);
//databaseFile.mkdirs();
//databaseFile.delete();
SQLiteDatabase.loadLibs(mContext);
String dbPath = mContext.getDatabasePath("ec.db").getPath();
//databaseFile.delete();
SQLiteDatabase.loadLibs(mContext);
//mDataBase = SQLiteDatabase.openOrCreateDatabase(databaseFile, "123", null);
//mDataBase = SQLiteDatabase.openDatabase(mPath, "123",null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
mDataBase = SQLiteDatabase.openDatabase(dbPath, "123", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
return mDataBase != null;
}
@Override
public synchronized void close() {
if (mDataBase != null)
mDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
最佳答案
您正在引用 123456Sa
的密码字符串值,但是您在 createDataBase
中的调用使用 123
的值作为 getWritableDatabase
的密码。
关于android-sqlite - 编译时 net.sqlcipher.database.SQLiteException : file is not a database: ,: select count(*) from sqlite_master,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51726067/
我有一段代码: try { //sniping out a bunch of irrelevant code here result = cmd.ExecuteScalar();
我有一项服务(在下面列出)正在尝试创建数据库表。当 PlayerTable 的 onCreate() 中的 sql 被执行时,我得到一个异常我不明白。下面列出了所有代码。基本上,服务启动,获取一个 S
从SQLite查询数据时,它说: SQLite错误提供给命令的参数不足 我认为这是一个错误,或者错误消息具有误导性。 因为我只有一个参数并且正在提供它,所以我无法理解问题出在哪里。 这是我的代码: p
我正在尝试使用 SQLite 运行 NHibernate 集成测试。 NHibernate 的 SchemaExport 将根据我的映射文件为我设置数据库。除了我的触发器之外,这工作得很好。 .hbm
我想执行一个 ManagedQuery 但我在我的日志中收到一个错误: 查询 Cursor cursor = managedQuery(GroceryListContentProvider.NOTE
我明白了 android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling
当我尝试访问我的 View 时出现此错误 我已经使用它构建了我的数据库/ View CREATE TABLE Boxer( BoxerId INTEGER PRIMARY KEY AUTOINCREM
我有这个代码: String sql="UPDATE LAST_OPEN SET LAST_OPEN="+DATE+" WHERE STUDENT_ID ="+STUDENT_I
我在 SQLite 数据库上工作得很好,但现在我在使用查询时遇到了问题。例如,如果使用这样的查询: SQLiteDatabase db = mHelper.getReadableDatabase();
谁知道这是什么意思?我正在尝试在 onActivityResult() 中启动事务以根据收到的结果插入一行。 03-05 15:39:51.937: ERROR/Database(2387): Fai
插入sqlite3数据库失败的可能原因是什么?来自 SQLiteException 的跟踪并不是特别有用。 是否有任何方法可以更好地了解导致异常的原因? 创建表格的位置(抱歉任何不稳定的间距): ht
我正在 try catch “android.database.sqlite.SQLiteException:错误代码 5:数据库已锁定”异常: try { db.insert
我最近在市场上发布了一个应用程序。从开发者控制台看来,我的用户中大约有 1-2% 遇到了这个问题。 1-2% 很小,但人们更倾向于在某些东西不起作用时发表评论,而不是在它起作用时发表评论,这可能会对下
@SuppressLint({"RxLeakedSubscription", "RxSubscribeOnError"}) public static long pushAppointmentsToC
这是从SQLiteDatebase获取表RECORD的代码。在 try block 中出现问题并且总是抛出 SQLiteException。我在这里想做的就是将表“RECORD”的每一行转换为字符串并
我整个上午都在研究此错误的其他实例,但到目前为止我所尝试的一切都不起作用。这可能是显而易见的事情,因为我对此很陌生。 我正在尝试返回 GET_ALL_INGREDIENTS 查询的结果。然后我会将其放
我有一个包含两个表的数据库,每次我尝试向第二个表添加新项目时,它都会说没有这样的表。请帮忙。 数据库助手: @Override public void onCreate(SQLiteDatab
所以我对 SQL 很陌生。我正在尝试将 xml 文件放入我可以搜索的数据库中。我有语法错误,但看不到它/不够熟悉,无法看到它。这是我的 onCreate 方法 protected void onCr
大家好,我在数据库处理程序类中有这个方法,这个类的作用是从产品表中返回产品的 ID。但是,我收到了这个 sqliteException,我不知道为什么。请指教,谢谢。 private stat
我正在构建一个锻炼日志应用程序作为一个项目。我正在尝试将锻炼名称插入数据库。在提示用户添加练习之前。目前它显示“出现问题错误”,然后应用程序崩溃。 下面是Logcat中的错误 android.data
我是一名优秀的程序员,十分优秀!