oracle 通过 Android 应用程序连接到 OracleDB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5727857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to an OracleDB via an Android app
提问by Eriatolc
Thans for looking, I hope you could help me.
比寻找,我希望你能帮助我。
Currently, I want to get some data from an OracleDB server (on the LAN) from my Android app. I'm using JDBC with the ojdbc14.jar and the following code in my Android app and the stackTrace I have with the logcat :
目前,我想从我的 Android 应用程序的 OracleDB 服务器(在 LAN 上)获取一些数据。我将 JDBC 与 ojdbc14.jar 和我的 Android 应用程序中的以下代码以及我与 logcat 一起使用的 stackTrace 一起使用:
http://pastebin.archlinux.fr/432118
http://pastebin.archlinux.fr/432118
As you can see, there is a big exception, and I'm not be able to fix it...
如您所见,有一个很大的例外,我无法修复它...
Has someone already succeeded in a OracleDB connection with his Android app and without webservices ? Could someone help me fixing this Exception ?
有人已经在没有网络服务的情况下通过他的 Android 应用程序成功地建立了 OracleDB 连接吗?有人可以帮我解决这个异常吗?
For information : I've tried to change the ojdbc driver (the worst thing I've ever done >.>), and I checked the URL validity.
有关信息:我尝试更改 ojdbc 驱动程序(我做过的最糟糕的事情 >.>),并且我检查了 URL 有效性。
Thanks for helping...
谢谢你的帮助...
EDIT : The application will have to get data from the OracleDB, and store it on the local SQLite DB of Android, because the Android device will be disconnected of the LAN (and I don't want to make the data accessible from web [3G]). Once disconnected, the app will work with the local data on SQLite. When the user's activity is finished, the device will be reconnected to the LAN and the app syncs the edited SQLite local data with the main Oracle DB server. SQLite <-- local --> App <-- when connected/sync ---> OracleDB
编辑:应用程序必须从 OracleDB 获取数据,并将其存储在 Android 的本地 SQLite DB 上,因为 Android 设备将与 LAN 断开连接(我不想让数据可从网络访问 [3G ])。断开连接后,该应用程序将使用 SQLite 上的本地数据。当用户的活动完成时,设备将重新连接到 LAN,应用程序将编辑的 SQLite 本地数据与主 Oracle DB 服务器同步。SQLite <-- 本地 --> 应用程序 <-- 连接/同步时 ---> OracleDB
回答by Eric Jensen
Oracle actually has a product specifically designed for syncing the Oracle Database with mobile devices. It's called mobile server.
Oracle 实际上有一个专门设计用于将 Oracle 数据库与移动设备同步的产品。它被称为移动服务器。
However the usage model is slightly different from what you're describing; instead of connecting directly to Oracle Database, you would use a local Berkeley DB or SQLite database, and then mobile server would sync that with the Oracle Database.
但是,使用模型与您所描述的略有不同;您可以使用本地 Berkeley DB 或 SQLite 数据库,而不是直接连接到 Oracle 数据库,然后移动服务器会将其与 Oracle 数据库同步。
It can run as a separate process that automatically handles sync, or you can use API calls to control sync from within your program. If that sounds like something that could be useful to you, check it out here.
它可以作为自动处理同步的单独进程运行,或者您可以使用 API 调用从您的程序中控制同步。如果这听起来对您有用,请在此处查看。
You can download it from the download tab and try it out.
您可以从下载选项卡下载并试用。
Best of luck with solving your problem.
祝您好运解决您的问题。
Regards
问候
Eric, Oracle PM
埃里克,甲骨文产品经理
回答by Eriatolc
I've found the answer ! The product Oracle Database Lite is the solution. I explain...
我找到了答案!Oracle Database Lite 产品就是解决方案。我解释...
The Oracle Database Lite is a big product, with an unreadable documentation. Impossible for me to understand how it works. But, I've tried to install it. And, in the install folders, there is a jdbc folder.
Oracle Database Lite 是一个大产品,文档难以阅读。我不可能理解它是如何工作的。但是,我试过安装它。而且,在安装文件夹中,有一个 jdbc 文件夹。
There, you will find an ojdbc14.jar. Use it in your project instead of the ojdbc14.jar found on the classical Oracle webpage. And it works !
在那里,您会找到一个 ojdbc14.jar。在您的项目中使用它而不是在经典 Oracle 网页上找到的 ojdbc14.jar。它有效!
You will be able to connect an Oracle DB via your Android app, using JDBC.
您将能够使用 JDBC 通过您的 Android 应用程序连接 Oracle DB。
Thanks for all, Best regards,
谢谢大家,最好的问候,
Eriatolc
埃里亚托克
回答by Brainsbot
ORACLE DATABASE CONNECTION WITH ANDROID THROUGH LAN
甲骨文数据库通过局域网与安卓连接
Grant Some Manifest Permissions
授予一些清单权限
<permission
android:name="info.android.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="info.android.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
MainActivity Class
主活动类
package example.com.myapplication;
import java.sql.Connection;
import java.sql.DriverManager;
import android.os.StrictMode;
public class MainActivity extends AppCompatActivity {
private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver";
private static final String DEFAULT_URL = "jdbc:oracle:thin:@192.168.0.1:1521:xe";
private static final String DEFAULT_USERNAME = "system";
private static final String DEFAULT_PASSWORD = "oracle";
private Connection connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
TextView tv = (TextView) findViewById(R.id.hello);
try {
this.connection = createConnection();
e.Log("Connected");
Statement stmt=connection.createStatement();
ResultSet rs=stmt.executeQuery("select * from cat");
while(rs.next()) {
System.out.println("hello : " + rs.getString(1));
}
connection.close();
}
catch (Exception e) {
e.Log(""+e);
e.printStackTrace();
}
}
public static Connection createConnection(String driver, String url, String username, String password) throws ClassNotFoundException, SQLException {
Class.forName(driver);
return DriverManager.getConnection(url, username, password);
}
public static Connection createConnection() throws ClassNotFoundException, SQLException {
return createConnection(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
}
}
Prerequisite are: Note there is no need to add dependency lib ojdbc14.jar just copy ojdbc14.jar to your JAVA_HOME jre -> lib -> ext & paste here ojdbc14.jar then first manually check jdbc connection by cmd/terminal make any simple java program http://www.javatpoint.com/example-to-connect-to-the-oracle-database
先决条件是:注意不需要添加依赖库 ojdbc14.jar 只需将 ojdbc14.jar 复制到您的 JAVA_HOME jre -> lib -> ext 并粘贴到此处 ojdbc14.jar 然后首先通过 cmd/terminal 手动检查 jdbc 连接做任何简单的 java程序 http://www.javatpoint.com/example-to-connect-to-the-oracle-database