Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I am not that experienced in Sybase systems but I am keen to learn.

I have a simple android application that I am trying to connect to a Ultralight DB. This DB is stored in my project built on Android Studio 0.3.1. I've added the file ultralitejni12.jar in my libs and added it as library and I am able to do reference import in my java class without a problem. I even get intellisense help on this. Then I copied the DB (with extension <*.udb>) file into my assets in the project directory. The full path in windows explorer looks like this: (C:AndroidDevAnroidStudioSampleAppProjectSampleAppbuildexploded-bundlesComAndroidSupportAppcompatV71900.aar). I don't know if this should be the right directory to put it but believe me I already tried the 'libs' location but to no avail. The code I am using to connect to the database came straight from Sybase after Googling around but it's generating funny errors like ; "Gradle: cannot find symbol class ULjException" "Gradle: package com.ianywhere.ultralitejni12 does not exist".

Every attempt to rebuild does nothing for me. Please help...

    package com.lebel.sampleapp;

//import android.content.Context;
//import com.ianywhere.ultralitejni12.*;
//import java.sql.Connection;
//import static com.ianywhere.ultralitejni12.DatabaseManager.*;

import android.content.Context;

import com.ianywhere.ultralitejni12.ConfigFileAndroid;
import com.ianywhere.ultralitejni12.Connection;
import com.ianywhere.ultralitejni12.DatabaseManager;
import com.ianywhere.ultralitejni12.ULjException;

import static com.ianywhere.ultralitejni12.DatabaseManager.connect;
import static com.ianywhere.ultralitejni12.DatabaseManager.createConfigurationFileAndroid;

/**
 * Created by Lebel on 11/11/13.
 */

public class Database{
    private static Database _instance = null;
    private static Connection _dbconn;
    private static final int defaultPort = 2639;
    private static final String defaultUsername = "dba";
    private static final String defaultPassword = "sql";
    private static final String db = "lebeldb.udb";
    private static final String LOG_EXCEPTION = "Database Connection Error";
    Context _context;
    private Database(Context context) throws ULjException {

        _context = context;
        if( _dbconn == null ){
            ConfigFileAndroid config;
            config = createConfigurationFileAndroid(db, _context);
            config.setConnectionString("haa");
            config.setUserName(defaultUsername);
            config.setPassword(defaultPassword);
            config.setPageSize(8192);
            try{
                _dbconn = connect(config);
            }
            catch(Exception e) {
                _dbconn = DatabaseManager.createDatabase(config);
            }
    }

    }
    protected static Database getInstance(Context context) throws ULjException {
        if(_instance == null){
            _instance = new Database(context);
        }
        return _instance;
    }
}

Since the above class is a singleton my calling code in the Activity that I'm using is as follow:

package com.lebel.sampleapp;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.ianywhere.ultralitejni12.*;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lebel on 11/11/13.
 */
public class actStaffList extends Activity {
    private List<String> StaffList;
    //private static Context context;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lyt_viewstaff);
        //context = this.getApplicationContext();
        try {
            setupViews();
        } catch (ULjException e) {
            e.printStackTrace();
        }
    }

    private void setupViews() throws ULjException {
        try {
            Connection _dbconn = (Connection) Database.getInstance(this.getApplicationContext());
            String qry = "SELECT TOP 10  Test FROM Test";
            PreparedStatement ps = _dbconn.prepareStatement(qry);
            ResultSet rs = ps.executeQuery();
            StaffList = new ArrayList<String>();
            while (rs.next()) {
                //StaffList.add(rs.getInt(1));
                //StaffList.add(rs.getInt(1));
                //StaffList.add(rs.getString(rs.getOrdinal("StaffID")));
                StaffList.add(rs.getString(0));
            }
            rs.close();
            ps.close();
            // Populate listview here
            ListView lv = (ListView) findViewById(R.id.lvStaffList);
            lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, StaffList));
//        } catch (ULjException e) {
//            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}

asked 12 Nov '13, 08:31

lebel's gravatar image

lebel
16114
accept rate: 0%

I am not familiar with Android Studio, so I can only suggest posting to a forum concerned with Android Studio. Or possibly someone else on this forum can help.

I does seem strange that intellisense recognizes the UltraLite package, but Gradle does not. The location of the .udb should not have any effect on building the project. You may need to copy the .udb file somewhere at runtime that UltraLite can open it, but that is a runtime issue, rather than a build issue.

(12 Nov '13, 09:50) Andy Quick

libs is the correct folder to place the ultralitejni12.jar file.

Have you also copied the shared library object libultralitej12.so into the project? In your libs folder, you should create a folder called armeabi and place the shared object in that location. The shared object file can be found at %SQLANY12%\UltraLite\UltraLiteJ\Android\ARM.

The sample CustDB Android project uses this structure and can be found at %SQLANYSAMP12%\Samples\UltraLiteJ\Android\CustDB

permanent link

answered 13 Nov '13, 10:22

Mikel%20Rychliski's gravatar image

Mikel Rychliski
2.1k1641
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×162
×159
×79

question asked: 12 Nov '13, 08:31

question was seen: 4,229 times

last updated: 13 Nov '13, 19:17