GVKun编程网logo

无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'

8

在这篇文章中,我们将带领您了解无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'的全貌

在这篇文章中,我们将带领您了解无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'的全貌,同时,我们还将为您介绍有关71.You configured the Flash Recovery Area for your database. The database instance has been started、@EnableAsync annotation metadata was not injected、A context-aware personalized travel recommendation system based on geotagged social media data mi...、Android getReadableDatabase() 和 getWritableDatabase()分析对比的知识,以帮助您更好地理解这个主题。

本文目录一览:

无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'

无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'

在我的Android应用程序中,资产文件夹中有一个预定义的数据库。

我创建了一个表android_metadata,该表的列名为locale并且有一条记录en_US

在我的应用程序中,用户应输入他/她的详细信息,然后单击“保存”按钮。

当单击保存按钮时,出现以下错误;

10-21 09:37:06.010:E / SQLiteLog(6278):(11)数据库损坏,位于[00bb9c9ce4]的第50741行10-21
09:37:06.010:E / SQLiteLog(6278):(11)数据库损坏[00bb9c9ce4]的第50780行10-21
09:37:06.010:E / SQLiteLog(6278):(11)语句在16:中止。 37:06.160:E /
SQLiteDatabase(6278):无法打开数据库’/data/data/my.easymedi.controller/databases/EasyMediInfo.db’。10-21
09:37:06.160:E /
SQLiteDatabase(6278):android.database.sqlite.SQLiteException:无法将db’/data/data/my.easymedi.controller/databases/EasyMediInfo.db’的语言环境更改为’
en_US’。10-21 09:37:06.160:E /
SQLiteDatabase(6278):位于android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:

我的DBHelper类正在关注;

package my.easymedi.db;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import my.easymedi.entity.Person;import android.content.ContentValues;import android.content.Context;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteException;import android.database.sqlite.SQLiteOpenHelper;import android.util.Log;import android.widget.Toast;public class DBHelper extends SQLiteOpenHelper { private static final String pkg = "my.easymedi.controller"; private static String DB_PATH = ""; private static String DB_NAME = "EasyMediInfo.db"; private static final int DB_VERSION = 1; private final Context myContext; private SQLiteDatabase myDatabase; public DBHelper(Context context) {  super(context, DB_NAME, null, DB_VERSION);  // this.myContext = context;  if (android.os.Build.VERSION.SDK_INT >= 4.2) {   DB_PATH = context.getApplicationInfo().dataDir + "/databases/";  } else {   DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";  }  this.myContext = context; } public void createDataBase() {  boolean dbExist = checkDataBase();  System.out.println("===" + dbExist + "===");  if (dbExist) {   // do nothing - database already exist  } else {   this.getReadableDatabase();   this.close();   try {    copyDataBase();    Log.d("CREATE_DB", "createDatabase database created");   } catch (IOException e) {    Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT)     .show();    Log.d("CREATE_DB", e.getMessage());   }  } } private void copyDataBase() throws IOException {  System.out.println("***copy db***");  InputStream databaseInput = null;  /* Path to copy the database */  String outFileName = DB_PATH + DB_NAME;  /* open the empty database as an output stream */  OutputStream databaseOutput = new FileOutputStream(outFileName);  /* open the local database as the input stream */  databaseInput = myContext.getAssets().open(DB_NAME);  /* Transfer byte from byte from input file to output file */  byte[] buffer = new byte[1024];  int length = databaseInput.read(buffer);  while (length > 0) {   databaseOutput.write(buffer, 0, length);   //databaseOutput.flush();  }  databaseOutput.flush();  databaseInput.close();  databaseOutput.close(); } private boolean checkDataBase() {  File dbFile = new File(DB_PATH + DB_NAME);  return dbFile.exists();  /*SQLiteDatabase checkDB = null;  try {    String myPath = DB_PATH + DB_NAME;    checkDB = SQLiteDatabase.openDatabase(myPath, null,            SQLiteDatabase.NO_LOCALIZED_COLLATORS);  } catch (SQLiteException e) {    Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT)            .show();    Log.d("Check_DB", e.getMessage());  }  if (checkDB != null) {    String str = "checked";    System.out.println("====" + str + "====");    checkDB.close();  }  return checkDB != null ? true : false;*/ } /* Open the database */ public boolean openDataBase() {  String myPath = DB_PATH + DB_NAME;  Toast.makeText(myContext, myPath, Toast.LENGTH_SHORT).show();  myDatabase = SQLiteDatabase.openDatabase(myPath, null,   SQLiteDatabase.OPEN_READWRITE);  if (myDatabase != null) {   System.out.println("====database opened====");  } else {   System.out.println("====error opening database====");  }  return myDatabase != null ? true : false; } public void closeDatabase() {  if (myDatabase != null) {   myDatabase.close();  } } @Override public void onCreate(SQLiteDatabase db) {  // TODO Auto-generated method stub } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {  // TODO Auto-generated method stub } public boolean insertIntoDatabase(String table, ContentValues values) {  try {   myDatabase.insert(table, null, values);   Log.d("INSERT", "Information Saved");   return true;  } catch (Exception e) {   // TODO Auto-generated catch block   Log.d("INSERT", e.toString());   return false;  } }}

这是我的保存按钮的代码段;

case R.id.btnSave: personName = etName.getText().toString();date_of_birth = tvDOB.getText().toString();age = tvAge.getText().toString();int selected_rb_ID = genderGrp.getCheckedRadioButtonId();RadioButton rb = (RadioButton) findViewById(selected_rb_ID);gender = rb.getText().toString();bloodGrp = spiBloodGrp.getSelectedItem().toString();Person person = new Person();person.setName(personName);person.setDate_of_birth(date_of_birth);person.setAge(age);person.setGender(gender);person.setBloodGrp(bloodGrp);ContentValues values = new ContentValues();values.put(COLUMN_PERSON_NAME, person.getName());values.put(COLUMN_DOB, person.getDate_of_birth());values.put(COLUMN_AGE, person.getAge());values.put(COLUMN_GENDER, person.getGender());values.put(COLUMN_BLOODGRP, person.getBloodGrp());DBHelper dbHelper = new DBHelper(this);dbHelper.createDataBase();dbHelper.openDataBase();if (dbHelper.insertIntoDatabase("EMPerson", values)) { Toast.makeText(  getApplicationContext(),  "Data has been saved successfully",  Toast.LENGTH_SHORT ).show();} else { Toast.makeText(  getApplicationContext(),  "Oops ! Try again",  Toast.LENGTH_SHORT ).show();}dbHelper.closeDatabase();break;

在我的主要活动中,我通过调用此代码段来创建数据库。

final DBHelper helper = new DBHelper(this);helper.createDataBase();

该错误的含义是什么,我该如何解决?

答案1

小编典典

您的copyDataBase()函数EasyMediInfo.db从资产文件夹复制db()。看来数据库是使用不同于的语言环境创建的''en_US''

编辑

尝试更改:

myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

至:

myDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE);

71.You configured the Flash Recovery Area for your database. The database instance has been started

71.You configured the Flash Recovery Area for your database. The database instance has been started

71.You configured the Flash Recovery Area for your database. The database instance has been started in ARCHIVELOG mode and the LOG_ARCHIVE_DEST_1 parameter is not set. What will be the implications on the archiving and the location of archive redo log files?  A.Archiving will be disabled because the destination for the redo log files is missing. B.The database instance will shut down and the error details will be logged in the alert log file. C.Archiving will be enabled and the destination for the archived redo log file will be set to the Flash Recovery Area implicitly. D.Archiving will be enabled and the location for the archive redo log file will be created in the default location $ORACLE_HOME/log. 答案:C 解析:如果打开归档的话,并且没有指定归档路径的话,那么默认就是在闪回恢复区,LOG_ARCHIVE_DEST_n,n的取值范围1~31

@EnableAsync annotation metadata was not injected

@EnableAsync annotation metadata was not injected

在初始化 spring 事务部分碰到该错误,详细错误信息如下:

警告: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''org.springframework.context.annotation.internalAsyncAnnotationProcessor'' defined in org.springframework.scheduling.annotation.ProxyAsyncConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ''asyncAdvisor'' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
	at org.eclipse.jetty.server.Server.doStart(Server.java:282)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
	at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
	at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ''asyncAdvisor'' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 28 more
Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.util.Assert.notNull(Assert.java:112)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591.CGLIB$asyncAdvisor$0(<generated>)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591$$FastClassBySpringCGLIB$$ed8c37b9.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591.asyncAdvisor(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 29 more

十二月 16, 2015 11:42:21 下午 org.springframework.web.context.ContextLoader initWebApplicationContext
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ''org.springframework.context.annotation.internalAsyncAnnotationProcessor'' defined in org.springframework.scheduling.annotation.ProxyAsyncConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ''asyncAdvisor'' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:220)
	at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:615)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:465)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:434)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:782)
	at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:424)
	at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:774)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:249)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
	at org.eclipse.jetty.server.Server.doStart(Server.java:282)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedAdapter.start(JettyEmbeddedAdapter.java:67)
	at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
	at net.sourceforge.eclipsejetty.starter.embedded.JettyEmbeddedLauncherMain.main(JettyEmbeddedLauncherMain.java:42)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method ''asyncAdvisor'' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 28 more
Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected
	at org.springframework.util.Assert.notNull(Assert.java:112)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration.asyncAdvisor(ProxyAsyncConfiguration.java:45)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591.CGLIB$asyncAdvisor$0(<generated>)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591$$FastClassBySpringCGLIB$$ed8c37b9.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
	at org.springframework.scheduling.annotation.ProxyAsyncConfiguration$$EnhancerBySpringCGLIB$$82eb591.asyncAdvisor(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 29 more
错误原因:

在 spring 的配置文件 applicationContext.xml 中,配置包扫描器时,使用了 *, 想扫描所有的包;而这种方式有可能扫描到 spring 自带的包,造成错误 (自我理解,不对的话求教育)

改动前:

<!-- 包扫描器 -->
<context:component-scan base-package="*"/>
改动后 (具体指定了要扫描的包):

<!-- 包扫描器 -->
<context:component-scan base-package="com.git.*"/>

A context-aware personalized travel recommendation system based on geotagged social media data mi...

A context-aware personalized travel recommendation system based on geotagged social media data mi...

文章简介:利用社交网站Flickr上照片的geotag信息将这些照片聚类发现城市里的旅游景点,通过各照片的拍照时间得到用户访问某景点时的时间上下文和天气上下文(利用时间和public API of Wunderground),将访问景点的上下文进行排序得到popular的上下文作为景点的上下文。在给用户作推荐时,首先得到用户当前的上下文或者要访问景点的上下文,利用上下文匹配出一些景点,然后在这些景点里头根据user-based collaborative filtering方法进行推荐,user-based collaborative filtering中用户对景点的评分使用用户访问某景点的次数。

The architecture behind our approach is configured into various modular tasks to carry out different operations as depicted in Figure 1.

We find tourist locations using spatial proximity of photos and enrich the aggregated locations with semantic annotations using textual tags annotated to photos in combination with information provided by Web services. Profiles of locations are built to describe the contexts in which they have been visited. To derive temporal context, geotags and temporal tags annotated with photos are exploited, whereas to derive weather context, we query thirdparty weather Web services to retrieve weather conditions. Relationship between users and locations is drawn to model users’ travel preferences. Then, these users’ preferences are used to estimate the similarities among users. For making recommendations, first we filter the locations based on contextual constraints, and then rank the locations by personalized score. A measure is defined to identify similar users in previously visited cities and aggregate these users’ opinions to obtain personalized score for each location in a target city for the target user.

 

Android getReadableDatabase() 和 getWritableDatabase()分析对比

Android getReadableDatabase() 和 getWritableDatabase()分析对比

Android getReadableDatabase() 和 getWritableDatabase()分析对比

Android使用getWritableDatabase()和getReadableDatabase()方法都可以获取一个用于操作数据库的sqliteDatabase实例。(getReadableDatabase()方法中会调用getWritableDatabase()方法)

其中getWritableDatabase() 方法以读写方式打开数据库,一旦数据库的磁盘空间满了,数据库就只能读而不能写,倘若使用的是getWritableDatabase() 方法就会出错。

getReadableDatabase()方法则是先以读写方式打开数据库,如果数据库的磁盘空间满了,就会打开失败,当打开失败后会继续尝试以只读方式打开数据库。如果该问题成功解决,则只读数据库对象就会关闭,然后返回一个可读写的数据库对象。

源码如下:

/** 
   * Create and/or open a database that will be used for reading and writing. 
   * Once opened successfully,the database is cached,so you can call this 
   * method every time you need to write to the database. Make sure to call 
   * {@link #close} when you no longer need it. 
   * 
   * <p>Errors such as bad permissions or a full disk may cause this operation 
   * to fail,but future attempts may succeed if the problem is fixed.</p> 
   * 
   * @throws sqliteException if the database cannot be opened for writing 
   * @return a read/write database object valid until {@link #close} is called 
   */ 
  public synchronized sqliteDatabase getWritableDatabase() { 
    if (mDatabase != null && mDatabase.isopen() && !mDatabase.isReadOnly()) { 
      return mDatabase; // The database is already open for business 
    } 
 
    if (mIsInitializing) { 
      throw new IllegalStateException("getWritableDatabase called recursively"); 
    } 
 
    // If we have a read-only database open,someone Could be using it 
    // (though they shouldn't),which would cause a lock to be held on 
    // the file,and our attempts to open the database read-write would 
    // fail waiting for the file lock. To prevent that,we acquire the 
    // lock on the read-only database,which shuts out other users. 
 
    boolean success = false; 
    sqliteDatabase db = null; 
    if (mDatabase != null) mDatabase.lock(); 
    try { 
      mIsInitializing = true; 
      if (mName == null) { 
        db = sqliteDatabase.create(null); 
      } else { 
        db = mContext.openorCreateDatabase(mName,mFactory); 
      } 
 
      int version = db.getVersion(); 
      if (version != mNewVersion) { 
        db.beginTransaction(); 
        try { 
          if (version == 0) { 
            onCreate(db); 
          } else { 
            onUpgrade(db,version,mNewVersion); 
          } 
          db.setVersion(mNewVersion); 
          db.setTransactionSuccessful(); 
        } finally { 
          db.endTransaction(); 
        } 
      } 
 
      onopen(db); 
      success = true; 
      return db; 
    } finally { 
      mIsInitializing = false; 
      if (success) { 
        if (mDatabase != null) { 
          try { mDatabase.close(); } catch (Exception e) { } 
          mDatabase.unlock(); 
        } 
        mDatabase = db; 
      } else { 
        if (mDatabase != null) mDatabase.unlock(); 
        if (db != null) db.close(); 
      } 
    } 
  } 
 
  /** 
   * Create and/or open a database. This will be the same object returned by 
   * {@link #getWritableDatabase} unless some problem,such as a full disk,* requires the database to be opened read-only. In that case,a read-only 
   * database object will be returned. If the problem is fixed,a future call 
   * to {@link #getWritableDatabase} may succeed,in which case the read-only 
   * database object will be closed and the read/write object will be returned 
   * in the future. 
   * 
   * @throws sqliteException if the database cannot be opened 
   * @return a database object valid until {@link #getWritableDatabase} 
   *   or {@link #close} is called. 
   */ 
  public synchronized sqliteDatabase getReadableDatabase() { 
    if (mDatabase != null && mDatabase.isopen()) { 
      return mDatabase; // The database is already open for business 
    } 
 
    if (mIsInitializing) { 
      throw new IllegalStateException("getReadableDatabase called recursively"); 
    } 
 
    try { 
      return getWritableDatabase(); 
    } catch (sqliteException e) { 
      if (mName == null) throw e; // Can't open a temp database read-only! 
      Log.e(TAG,"Couldn't open " + mName + " for writing (will try read-only):",e); 
    } 
 
    sqliteDatabase db = null; 
    try { 
      mIsInitializing = true; 
      String path = mContext.getDatabasePath(mName).getPath(); 
      db = sqliteDatabase.openDatabase(path,mFactory,sqliteDatabase.OPEN_READONLY); 
      if (db.getVersion() != mNewVersion) { 
        throw new sqliteException("Can't upgrade read-only database from version " + 
            db.getVersion() + " to " + mNewVersion + ": " + path); 
      } 
 
      onopen(db); 
      Log.w(TAG,"Opened " + mName + " in read-only mode"); 
      mDatabase = db; 
      return mDatabase; 
    } finally { 
      mIsInitializing = false; 
      if (db != null && db != mDatabase) db.close(); 
    } 
  } 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

今天关于无法将数据库'/data/data/my.easymedi.controller/databases/EasyMediInfo.db'的语言环境更改为'en_US'的讲解已经结束,谢谢您的阅读,如果想了解更多关于71.You configured the Flash Recovery Area for your database. The database instance has been started、@EnableAsync annotation metadata was not injected、A context-aware personalized travel recommendation system based on geotagged social media data mi...、Android getReadableDatabase() 和 getWritableDatabase()分析对比的相关知识,请在本站搜索。

本文标签: