我正在使用node.js v6 LTS和npm jdbc包连接到hortonworks上的Apache phoenix。 我的代码如下: -
var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');
var jar1='/home/ashish/seed-project-phoenix/public/drivers/phoenix-core-4.7.0.2.5.6.0-40.jar';
var jar2='/home/ashish/seed-project-phoenix/public/drivers/phoenix-queryserver-client-4.7.0.2.5.6.0-40.jar';
var jar3='/home/ashish/seed-project-phoenix/public/drivers/hbase-client-1.1.2.2.5.6.0-40.jar';
if (!jinst.isJvmCreated()) {
// Add all java options required by your project here. You get one
//chance to setup the options before the first java call.
jinst.addOption("-Xrs");
// Add all jar files required by your project here. You get one chance to
// setup the classpath before the first java call.
jinst.setupClasspath([jar1,jar2,jar3]); // adding jars
}
var config = {
url:'jdbc:phoenix:ZK1,ZK2,ZK3:2181:/hbase-unsecure',
drivername: 'org.apache.phoenix.jdbc.PhoenixDriver'
};
var phoenixHbase = new JDBC(config);
phoenixHbase.initialize(function(err) {
if (err) {
console.log(err);
}
else{
console.log("connected to Apache phoenix ...");
}
});
但我收到以下错误: -
{ Error: Could not find class org.apache.phoenix.jdbc.PhoenixDriver
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.<clinit>(PhoenixEmbeddedDriver.java:74)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
at Error (native)
at JDBC.Pool.initialize (/home/ashish/seed-project-phoenix/node_modules/jdbc/lib/pool.js:135:10)
at /home/ashish/seed-project-phoenix/routes/app.js:71:18
at Layer.handle [as handle_request] (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/layer.js:95:5)
at /home/ashish/seed-project-phoenix/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/index.js:330:12)
at next (/home/ashish/seed-project-phoenix/node_modules/express/lib/router/index.js:271:10) cause: nodeJava_java_lang_NoClassDefFoundError {} }
{ Error: Error running static method
java.sql.SQLException: No suitable driver found for jdbc:phoenix:ZK1,ZK2,ZK3:2181:/hbase-unsecure
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at Error (native) cause: nodeJava_java_sql_SQLException {} }
根据我的说法,连接字符串应该没有问题,并且已根据版本添加了所有jar文件。
凤凰版: - 4.7.0.2.5.6.0-40 Hbase版本: - 1.1.2.2.5.6.0-40
如果有人做过类似的事情,请给出一些指示。