我是Android开发的新手。
我正在将一个PC应用程序移植到RealWear的HMT1 Android设备上。我不想重写我的代码,因此我将尝试使用Hibernate和H2db,这两者都应该在Android上运行。
不幸的是,我还没有找到关于如何在Android上安装H2的任何说明。 H2是.jar文件,到目前为止我只通过Android工作室使用APK。
如何在Android上安装H2?
增加学位
dependencies {
compile 'com.h2database:h2:1.4.196'
runtimeOnly 'com.h2database:h2:1.4.196'
}
h2在Android中完美运行,只需将依赖项添加到gradle.app即可。然后,您必须指明您要使用的数据库:
try{
Class.forName("org.h2.Driver");
}
catch(ClassNotFoundException e){System.out.println(e);}
try{
CONN_STR = "jdbc:h2:/data/data/com.example.example/data/dbfile;FILE_LOCK=FS;PAGE_SIZE=1024;CACHE_SIZE=8192";
conn = DriverManager.getConnection(CONN_STR);
}
catch (SQLException ex)
{
}