JDBC Plugin
This plugin allows you to execute simple queries against any database with a JDBC driver using Android. Due to the requirement of adding a driver JAR, it's not compatible with automated build services (like PhoneGap Build). You'll need to use PhoneGap CLI
The plugin provides a generic interface for using JDBC libraries with a PhoneGap plugin. The interface has a hook to a Java driver which does the actual work. JDBC drivers are available for many databases.
The main documentation and files for the plugin are here: https://github.com/arsmentis/cordova-plugin-jdbc. In this document, we will discuss how to use the plugin from AppStudio.
Begin by making sure the PhoneGap CLI toolchain is installed properly. Documentation for installing it is in the Install Tools section of this page: here.
Creating your AppStudio Project
Next, create a new project in AppStudio. You'll need to do a couple of extra steps:
1. Add the hook to configxml: Open configxml in Project Properties. Add the hook declaration just after <platform name="android">
<platform name="android"> <hook type="after_prepare" src="scripts/copyDriver.js" /> ... </platform>
2. Go into Preferences/PhoneGap and set 'Build Command' to cordova build.
3. Save your project.
4. From the run menu, choose Make Native App with PhoneGap CLI.
PhoneGap
AppStudio should now have created a phonegap folder in your project directory. This will contain all the build files for PhoneGap CLI. Each time you choose Make Native App with PhoneGap CLI, these files will be updated with the latest version of your code.
1. If you get a message in the Build window which says "No platforms add to this project", open up a cmd window in the phonegap folder and add Android as a platform:
cordova platform add android
Repeat Make Native App with PhoneGap CLI.
2. Add the following folders to the phonegap directory.
- spash: your splash screens.
- icons: your icons.
- libs: Put your JDBC driver here.
- scripts. Add a file called copyDriver.js to it with the following contents:
var fs = require('fs'); var path = require('path'); module.exports = function(context) { var libsPath = path.join(context.opts.projectRoot, 'libs'); var platformLibsPath = path.join(context.opts.projectRoot, 'platforms', 'android', 'libs'); var libs = fs.readdirSync(libsPath); libs.forEach(function (lib) { console.log('Copying libs/%s to platforms/android/libs...', lib); fs.createReadStream(path.join(libsPath, lib)) .pipe(fs.createWriteStream(path.join(platformLibsPath, lib))); }); };
3. To check if the PhoneGap toolchain is OK, by using the requirements command:
> cordova requirements Requirements check results for android: Java JDK: installed . Android SDK: installed Android target: installed android-22,android-23 Gradle: installed
3. If the build is successful, the apk file will be in phonegap/platforms/android/build/outputs/apk.
Example (BASIC)
Function Button1_onclick() jdbc.load("com.ibm.as400.access.AS400JDBCDriver", loadSuccess, loadFail) End Function Sub loadSuccess(data) console.log("success", data) End Sub Sub loadFail(data) console.log("fail", data) End Sub
Example (JavaScript)
Button1.onclick = function() { jdbc.load("com.ibm.as400.access.AS400JDBCDriver", loadSuccess, loadFail); }; function loadSuccess(data) { console.log("success", data); } function loadFail(data) { console.log("fail", data); }