在Android中使用SQL(JDBC)数据库 [英] Using SQL (JDBC) database in Android
问题描述
在一个旧的Java应用程序中,我有以下code连接到SQL数据库,并使用它的一些疑问:
In an old Java application I have the following code to connect to a SQL database and use it for some queries:
private Connection dbConnection = null;
System.setProperty("derby.system.home", "C:\\");
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
String strUrl = "jdbc:derby:BOOKSDB";
dbConnection = DriverManager.getConnection(strUrl);
Statement stmt = dbConnection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM BOOKS");
有没有机会使用它在Android?的文档说,有可能在一般情况下,是不它?但如何使用它?
Is there any chance to use it on Android? The documentation say that it is possible in general, isn't it? But how can one use it?
还是会更容易使其使用SQLite,而不是改变这一部分?我想这是许多工作要做,因为使用SQLite,你总是有一个指针,而不是一个ResultSet等等...
Or would it be easier to change this part so that it uses SQLite instead? I think this is much work to do because with SQLite, you always have a cursor instead of a ResultSet and so on ...
推荐答案
您可以在Android上使用JDBC,只要你提供一个JDBC驱动程序将在Android上运行。有href=\"http://$c$c.google.com/p/sqlite-jdbc/\" rel=\"nofollow\">应该运行在Android开源的纯Java JDBC驱动程序一个
You can use JDBC on android, provided you supply a JDBC driver that will run on Android. There is a open source pure-Java jdbc driver that should run on Android (although I haven't tried it myself). You will have to adapt the JDBC URL to connect to the sqlite db; that way you can use the local android database while making few changes to your data access code.
这篇关于在Android中使用SQL(JDBC)数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!