2

So people are probably going to tell me this is a bad idea, but I'd like to at least give it a go.

EDIT The intention of this app is that it can only work when the device is part of the same network the oracle db is on or is connected to the network via VPN. The information in the database is not going to be globally accessible, which is why I will need direct connection to the oracle db.

Now according to this thread

Connecting the oracle in android application

He was successful in querying the oracle db.

So I have a fairly basic class that when initialised will try to get a connection to my database.

package com.producermobile;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import android.util.Log;

public class ConnectOra {
    private Connection conn;
    private Statement stmt;
    public ConnectOra() throws ClassNotFoundException {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            String url = "jdbc:oracle:thin:@x.x.x.x:1521:PR10";
            this.conn = DriverManager.getConnection(url,"xxx","xxx");
            this.conn.setAutoCommit(false);
            this.stmt = this.conn.createStatement();
        } catch(SQLException e) {
            Log.d("tag", e.getMessage());
        }       
    }
    public ResultSet getResult() throws SQLException {
        ResultSet rset = stmt.executeQuery("select customer from customers");
        stmt.close();
        return rset;            
    }
}

And in my main activity onCreate method I have this

@Override
public void onCreate(Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
        ConnectOra db = new ConnectOra();
        ResultSet rs = db.getResult();
        ArrayList<String> list = new ArrayList<String>();
        while(rs.next()) {
            list.add(rs.getString(1));
        }
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, list));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);          
    } catch(Exception e) {

    }
}

In Eclipse I add the external ojdbc14.jar file to the build path.

However when I run

this.conn = DriverManager.getConnection(url,"xxx","xxx");

I receive the following exception

"Io exception: The Network Adapter could not establish the connection"

If however I create an instance of this class inside a standard java app with a main method, the connection works. Any ideas?

Community
  • 1
  • 1
PDStat
  • 5,513
  • 10
  • 51
  • 86
  • Note that many companies segregate their corporate network from wifi and will require an extra layer of security of also requiring the corporate VPN to be used. – YoYo May 31 '15 at 23:02

5 Answers5

2

Oracle has a product that provides both data sync with Oracle DB as well as offline capabilities; it's called Mobile Server

They way it works is, you just store your data in SQLite, and the Oracle client will handle sync. Of course you have to install and configure mobile server, and each new device will need to be provisioned, but once that is done, it "just works!"

There is a download tab in the link above, you can download and try it out of you like.

I hope that helps. Good luck with your problem.

Regards

Eric, Oracle PM

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Eric Jensen
  • 453
  • 4
  • 14
  • There is no any proper documentation to make apps. can you please provide links of examples to create app. I want to get some data from oracle to Android and display graphical view. – Pratik Butani Nov 11 '19 at 06:31
1

:) yes, I'm one that'll tell u it is a "bad" idea. IMHO, given that Android apps are intended to run on mobiles where connectivity might be an issue or be lost temporarily, I claim each good app should have some degree of offline capabilities. So you'd implement some very basic sync mechanism - as for instance demonstrated with the SampleSyncAdapter - which synchronizes with the apps local SQLite db.

I think this is the best way to go (also for the user experience).

Juri
  • 32,424
  • 20
  • 102
  • 136
  • Thanks, so this adapter is cloud based. Ok the intention of this app is that it can only work when the device is part of the same network the oracle db is on or is connected to the network via VPN. The information in the database is not going to be globally accessible, which is why I will need direct connection to the oracle db. – PDStat Feb 16 '11 at 11:32
  • regarding the exception you received: did you add the permission for accessing wifi to your app? – Juri Feb 16 '11 at 14:59
  • "connectivity might be an issue or be lost temporarily" Wouldn't this also be an issue for a wireless laptop or any network connection wired or wireless? If so should one also over complicate the architecture with extra stuff to avoid this mysterious "temporary loss of connectivity syndrome" that I have yet to see unless our companies network goes down? How is having a handheld computer via wireless any different from a normal desktop computer in the context of the office? – Kuberchaun Jan 14 '12 at 18:01
  • Of course if the requirements call for disconnected function that is a different story. – Kuberchaun Jan 14 '12 at 18:10
  • @StarShip3000 smartphones are normally more vulnerable. But it depends on your context. If you're only within the company's internal wireless network then it's one situation as if you were outside connected over mobile networks. But generally speaking, considering such offline storage pattern is in my opinion a must for improving the user experience in mobile apps. – Juri Jan 15 '12 at 12:01
1

Have you added in the AndroidManifest.xml the

uses-permission android:name="android.permission.INTERNET"

I've to create an app with the same constraint of connectivity and database. I've done this, and I've a lot of Exception (ArrayIndexOutOfBound during the connexion to the database.)

I use ojdbc14.jar for that. So, I "just have to" fix the Exception I have, and it would be OK...

For more information, see this topic

Community
  • 1
  • 1
Eriatolc
  • 197
  • 1
  • 1
  • 10
0

Another and much easier approach is to use a Virtual JDBC Driver that relies on a secure three-tier architecture: your JDBC code is sent through HTTP to a remote Servlet that filters the JDBC code (configuration & security) before passing it to the Oracle JDBC Driver. The result is sent you back through HTTP.

There are some free software that use this technique. Just Google "Android JDBC Driver over HTTP".

kaw
  • 77
  • 1
  • 4
0

Sorry to revive an old thread but I had this problem for a long time and finally fixed it. Just run eclipse or whatever you're developing in "as administrator" and the error will go away.

erebel55
  • 600
  • 2
  • 8
  • 25