【发布时间】:2014-12-01 09:23:06
【问题描述】:
我是 Android Studio 和 gradle 的新手。我有一个在 Eclipse 中部分工作的 android 项目。原始代码使用 Android 中的 derby 数据库。旧代码通过 JDBC 直接连接到 derby 数据库。由于纯粹的懒惰和实用性,我没有将数据库更改为 SQLite。现在我想更改代码以使用 SQLite 而不是 derby,并且我正在将该项目移植到 Android Studio 中。这就是乐趣的开始。当我尝试运行该应用程序时,Gradle 会抛出一个错误,提示“无法访问 javax.naming.referenceable 未找到的可引用类文件”。
Gradle 抱怨的代码如下:
package net.jxta.impl.cm.sql;
import java.io.IOException;
import java.net.URI;
import java.sql.SQLException;
import net.jxta.impl.util.threads.TaskManager;
import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
import org.apache.derby.jdbc.EmbeddedDataSource;
public class DerbyAdvertisementCache extends JdbcAdvertisementCache {
public DerbyAdvertisementCache(URI storeRoot, String areaName, TaskManager taskManager) throws IOException {
super(storeRoot, areaName, taskManager);
}
public DerbyAdvertisementCache(URI storeRoot, String areaName, TaskManager taskManager, long gcinterval, boolean trackDeltas) throws IOException {
super(storeRoot, areaName, taskManager, gcinterval, trackDeltas);
}
@Override
protected EmbeddedConnectionPoolDataSource createDataSource() {
if(!loadDbDriver( "org.apache.derby.jdbc.EmbeddedDriver")) {
throw new RuntimeException("Unable to loadDB driver: org.apache.derby.jdbc.EmbeddedDriver");
}
EmbeddedConnectionPoolDataSource dataSource = new EmbeddedConnectionPoolDataSource();
dataSource.setDatabaseName(dbDir.getAbsolutePath());
dataSource.setCreateDatabase("create");
System.err.println("Created derby cache");
return dataSource;
}
@Override
protected void shutdownDb() throws SQLException {
// annoyingly, shutting down a derby instance involves catching an exception
// and checking error codes to make sure it shut down "normally"
try {
EmbeddedDataSource dataSource = new EmbeddedDataSource();
dataSource.setDatabaseName(dbDir.getAbsolutePath());
dataSource.setShutdownDatabase("shutdown");
dataSource.getConnection();
} catch(SQLException e) {
// make sure we get the correct error codes
if(e.getErrorCode() != 45000 || !"08006".equals(e.getSQLState())) {
throw e;
}
}
}
}
你们能帮帮我吗? 谢谢 D
【问题讨论】: