node-jdbc
JDBC Wrapper for node.js
Latest Version
0.0.14
Support for adding multiple JARs to the classpath has been added. Use the libs array as shown in the initialize section below. As of release 0.0.9, the minimum version of node.js has been increased to v0.10. If you need to use this with node.js v0.8, use version 0.0.8 of node-jdbc.
Please visit node-jdbc for information on installing with npm.
Status
Usage
Check out test-hsqldb.js for a usage example.
Initialize
var jdbc = new ; // There are 3 methods to supply user/password combinations// In the URLvar configWithUserInUrl = // Required libpath: __dirname + 'path/to/jdbc.jar' drivername: 'com.java.driverclass' // Check your driver docs for supplying the user/password in the URL. url: 'url/to/database;user=SA;password=' // Optional libs: __dirname + 'path/to/other/jars.jar'; // As key/value pairs.var configWithUserInConfig = // Required libpath: __dirname + 'path/to/jdbc.jar' drivername: 'com.java.driverclass' url: 'url/to/database' // Optional libs: __dirname + 'path/to/other/jars.jar' user : 'SA' password: ''; // As an array.var configWithPropertiesInConfig = // Required libpath: __dirname + 'path/to/jdbc.jar' drivername: 'com.java.driverclass' url: 'url/to/database' // Optional libs: __dirname + 'path/to/other/jars.jar' properties: 'user' 'SA' 'password''' ; var config = // Required libpath: __dirname + 'path/to/jdbc.jar' drivername: 'com.java.driverclass' url: 'url/to/database' // Optional libs: __dirname + 'path/to/other/jars.jar' user: 'user' password: 'secret'; jdbc;
Open Connection, Execute Queries, Close
var { if err console; else if results console; jdbc; }; jdbc;
API
initialize(config, callback)
- see above example for config object
- callback(error)
open(callback)
- opens a new connection
- callback(error)
close(callback)
- closes any existing connection
- callback(error)
executeQuery(sql, callback)
- SELECT commands.
- callback(error, rset)
executeUpdate(sql, callback)
- table modifying commands (INSERT, UPDATE, DELETE, etc).
- callback(error, num_rows) where @num_rows is the number of rows modified