Skip to content

Instantly share code, notes, and snippets.

@jeffcogswell
Created Oct 5, 2017
Embed
What would you like to do?
CraZySacX/node-jdbc with hive JDBC driver in node.js
// Uses https://github.com/CraZySacX/node-jdbc
// Assumes you have already installed the JDK, hadoop, and hive!
// Just a quick demo with callback hell... Really you'll
// want to use async or something similar...
var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');
jinst.setupClasspath([
'/usr/local/hadoop/share/hadoop/common/hadoop-common-2.7.4.jar',
'/usr/local/apache-hive-1.2.2-bin/lib/hive-jdbc-1.2.2-standalone.jar'
])
var config = { url:'jdbc:hive2://localhost:10000' }
var hsqldb = new JDBC(config);
hsqldb.initialize(function(err) {
if (err) {
console.log('initialize error');
console.log(err);
return;
}
hsqldb.reserve(function(err, connObj) {
var conn = connObj.conn;
conn.createStatement(function(err, statement) {
if (err) {
console.log('Create Statement error');
console.log(err);
return;
}
statement.executeQuery('show tables', function(err, results) {
if (err) {
console.log('Execute Query error');
console.log(err);
hsqldb.release(connObj, function(err) {
if (err) {
console.log('Error releasing??!!');
console.log(err.message);
}
});
return;
}
results.toObjArray(function(err, resultArray) {
if (err) {
console.log('Error getting result as array');
}
else {
console.log(resultArray);
}
hsqldb.release(connObj, function(err) {
if (err) {
console.log('Error releasing??!!');
console.log(err.message);
}
});
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment