1

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 :

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 ?

For information : I've tried to change the ojdbc driver (the worst thing I've ever done >.>), and I checked the URL validity.

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

Eriatolc
  • 197
  • 1
  • 1
  • 10
  • The Stacktrace at Pastebin is no longer available - please don't use external services - include everything in your question. – Robert Jun 30 '11 at 12:01

3 Answers3

4

Oracle actually has a product specifically designed for syncing the Oracle Database with mobile devices. It's called mobile server.

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.

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.

You can download it from the download tab and try it out.

Best of luck with solving your problem.

Regards

Eric, Oracle PM

Verbeia
  • 4,400
  • 2
  • 23
  • 44
Eric Jensen
  • 453
  • 4
  • 14
  • I'll try this. Thank for the answer. I'll detail my answer because I want to do what your product do with my app :) Does your product could be in the app, or it must be outside of the Android app, install separatly by the customer ? – Eriatolc Apr 20 '11 at 09:27
  • 1
    It can all be installed at once. You can learn more about it here: http://bit.ly/dNmSKK You want the 'SQLite Mobile Client Guide,' Ch 4 is about Android – Eric Jensen Apr 20 '11 at 09:46
  • Hi. I've read a lot of the documentation but I think the doc is bad. Too much separate chapter and you lost the reader. And, more, important, in all the doc, I've never found the URL for the download page for the Oracle Database Lite Mobile Development Kit. O_o All the documentation is based on the fact we have downloaded something, but I don't find the link for Android. Can you help me ? – Eriatolc Apr 21 '11 at 13:18
  • you can get to the download from the link I posted above, but it's not very intuitive. Sorry about that! You can download mobile server here: http://bit.ly/fMDWMP, it is part of the Database Lite package. – Eric Jensen Apr 26 '11 at 19:24
1

I've found the answer ! The product Oracle Database Lite is the solution. I explain...

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.

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 !

You will be able to connect an Oracle DB via your Android app, using JDBC.

Thanks for all, Best regards,

Eriatolc

Eriatolc
  • 197
  • 1
  • 1
  • 10
  • I would not recommend connecting directly to your Oracle database from an Android phone using jdbc – Eric Jensen Apr 26 '11 at 19:29
  • Hi. Thx for answers. You're not the only one warning me for that. But, I repeat, the environment where this app will be use is very very particular. And this is the best solution. Also, the network architecture is safe for that, the Oracle DB is not connected to the internet, only on the LAN, and the connection on the LAN is very restricted. Thanks for helping. – Eriatolc Apr 26 '11 at 21:01
  • 1
    OK, if it's working for you, that's great. For a local LAN it would probably work fine. But for others who will read this, I want to point out that such a solution has limitations, and should generally not be used, for instance, to connect an Android phone to an Oracle Database over the internet. In that case, there are very serious security implications, not to mention stability and battery life issues if you attempt to transfer large amounts of data. Anyway I'm glad that I was able to help you find something that works for you! – Eric Jensen Apr 27 '11 at 06:06
  • This is exactly what I need! A direct connection to and Oracle database in LAN and where battery efficiency is not a concern. +1 – GxFlint Jul 15 '15 at 16:59
0

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

Brainsbot
  • 121
  • 1
  • 5