1

I have an Android app in which I wanted to use the DB2SimpleDataSource class contained in the db2jcc.jar / db2jcc4.jar file. I wanted to use this class to establish a connection to a DB2 Database, but I noticed a problem with that class. So I wrote a very simple app which just instantiate a DB2SimpleDataSource class object,in this way:

     import android.app.Activity;
     import android.os.Bundle;
     import android.view.Menu;
     import android.view.MenuItem;
     import com.ibm.db2.jcc.DB2SimpleDataSource;

     public class MainActivity extends Activity {

     @Override
     protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     DB2SimpleDataSource dataSource = new DB2SimpleDataSource(); //--->Error!
     }

Here's the problem:when I write this code,Eclipse shows no errors about this class,but when i run this app,it shows the following error in logcat:

 Could not find class 'com.ibm.db2.jcc.DB2SimpleDataSource' referenced 
 from method 'com.example.provadb2.MainActivity.onCreate'

Here's the process I used to add the JARs:

  1. Right click on project>Properties

  2. From Java Build Path,in Libraries tab,i clicked "Add External JARs" and pointed to the db2jcc.jar file

  3. In Order and Export tab,i checked db2jcc.jar

I also tried unchecking in the Order and Export tab but nothing happened.

I also tried to use db2jcc4.jar file,without results.

The "funny" thing is that,when I wrote the same code in Java instantiating a DB2SimpleDataSource class object,it worked without errors...Hope i can find some help,thanks.

Dan Kehn
  • 224
  • 1
  • 7
aldoalpha
  • 163
  • 10
  • you would find more help if you used gradle to build your project, rather than eclipse – njzk2 May 04 '15 at 20:02
  • 1
    i read this tutorial:http://www.ibm.com/developerworks/cloud/library/cl-mvc-mobile-bluemix-app/#N1017F in which DB2SimpleDataSource is used in Android without errors – aldoalpha May 04 '15 at 20:06
  • Is the driver jar packed with your android application and available at runtime? – swinkler May 04 '15 at 20:09
  • 1
    Could you be more specific?I wrote above the steps I made to add the jar in the java Build Path,do I have to set something else? – aldoalpha May 04 '15 at 20:11
  • Can you try this: http://stackoverflow.com/questions/1334802/how-can-i-use-external-jars-in-an-android-project – swinkler May 04 '15 at 20:17

1 Answers1

0

Your problem is at runtime, not compile time. Create a lib folder, add your external jars. Now click on individual jars and add to build path.