npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cordova-plugin-jdbc

v0.1.2

Published

Cordova Plugin for JDBC

Downloads

16

Readme

Cordova Plugin for JDBC

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).

Preparing Your Project

Verify you've added the Android platform to your Cordova project using cordova platform ls. If Android isn't listed as installed, add it with cordova platform add android --save.

Add the following hook to your project's config.xml:

    <platform name="android">
        <hook type="after_prepare" src="scripts/copyDriver.js" />
    </platform>

If a platform tag for Android already exists, you can simply add the hook tag to the existing platform tag.

Make a scripts folder in your project, and add copyDriver.js to the folder 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)));
  });
};

Make a libs folder in your project and add the driver JAR appropriate for your database. Add the plugin to your project with cordova plugin add cordova-plugin-jdbc. Finally, build your project with the command cordova build. Verify your driver JAR was copied to platforms/android/libs.

Using the Plugin

Calls to this plugin live under window.jdbc or just jdbc. All jdbc calls have a success and error callback as the final two function parameters. If the error callback is triggered, the sole parameter will be a string containing an error message.

load(driver, success, error)

Begin by loading your JDBC driver. Its documentation should reference the class name of the driver, which you'll pass as the first parameter. For instance, the PostgreSQL driver name is org.postgresql.Driver. You would load it like so:

jdbc.load('org.postgresql.Driver', success, error);

If loading is successful, the success callback is triggered.

connect(url, user, password, success, error)

Uses a driver specific JDBC url, user name, and password to connect to your database. For example:

jdbc.connect('jdbc:postgresql://10.0.2.2/mydb', 'testuser', 'securepassword', success, error);

If the connection is successful, the success callback is triggered. Any existing connection is disconnected.

disconnect(success, error)

Manually disconnect from the existing connection. Connections will be closed automatically when the app stops, but if you want to explicity close the connection, you can do so with the following code:

jdbc.disconnect(success, error);

Upon successful disconnection, the success callback is triggered.

isConnected(success, error)

Test if the JDBC plugin is connected to a database. Useful if your app stops, then resumes and you need to reestablish a connection.

jdbc.isConnected(success, error);

Upon completion, the success callback is triggered with a boolean parameter set to true if the plugin is connected, and false otherwise.

execute(sql, success, error)

Execute arbitrary SQL against the connected database. For example:

jdbc.execute('SELECT * FROM users', success, error)

Upon successful execution, the success callback will triggered with an array as its first parameter. If the statement produced results, each element of the array will contain an object with keys and values matching one row from the results. For example:

[
  {
    "id": 1,
    "name": "james",
    "last_login": "2016-05-22"
  },
  {
    "id": 2,
    "name": "george",
    "last_login": "2016-06-01"
  }
]

Warnings

Cordova apps are generally not difficult to decompile. This means that your database host, name, user, and password could easily be exposed by a knowledgable person if your app is public. If you use this plugin to access sensitive data, it's very important you restrict the rights of the database user so they can only perform the bare minimum of tasks needed for the app to function. You should assume that curious, or perhaps malicious people may connect to your database without using your app. Secure your data accordingly.

Additionally, the execute method has no protection against SQL injection. Be sure to sanitize your input appropriately for the underlying database.