从节点jdbc进行Redshift数据访问 [英] Redshift data access from node jdbc

查看:288
本文介绍了从节点jdbc进行Redshift数据访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用下面提到的代码从redshift进行数据处理时,我遇到了错误消息

I am getting below error when I try to data from redshift with the below mentioned code

var jdbc = new ( require('jdbc') );
var config = {
  libpath: 'C:/Users/ABCD/Desktop/jar/RedshiftJDBC41-1.1.6.1006.jar',
  //libs: [__dirname + 'path/to/other/jars.jar'],
  drivername: 'com.amazon.redshift.jdbc41.Driver',
  url: 'jdbc:redshift://examplecluster.abc123xyz789.us-west-2.redshift.amazonaws.com:5439/dev',
  user: 'xxxx',
  password: 'xxxxx'
};

jdbc.initialize(config, function(err, res) {
    if (err) {
    console.log(err);
  }
});

var genericQueryHandler = function(err, results) { 
  if (err) {
      console.log(err);
  } else if (results) {
      console.log(results);
}

jdbc.close(function(err) {
  if(err) {
    console.log(err);
  } else {
    console.log("Connection closed successfully!");
  }
});
};

jdbc.open(function(err, conn) {
if (conn) {
     // SELECT statements are called with executeQuery 
     jdbc.executeQuery("select * from information_schema.tables", genericQueryHandler);
}
});

错误:

C:\Users\ABCD> node redshift.js
C:\Users\ABCD\node_modules\jdbc\lib\jdbc.js:62> 
if(this._props.getPropertySync('user') === undefined){> 
  ^ TypeError: undefined is not a function

at JDBCConn.initialize
(C:\Users\ABCD\node_modules\jdbc\lib\jdbc.js:62:20)
at Object.<anonymous>
(C:\Users\ABCD\Desktop\AngularJS\redshift.js:15:6)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

能否让我知道上述节点jdbc在redshift中的使用是否存在问题?

Could you please let me know whether there is nay issue with the above mentioned node jdbc usage for redshift?

推荐答案

请注意,此答案仅适用于node-jdbc 0.0.15及更早版本.它不适用于node-jdbc 0.1.1或更高版本,因为该API已被完全重新设计并且不向后兼容.

尝试替换配置中的两行

  user: 'xxxx',
  password: 'xxxxx'

使用

  properties: [
    ['user', 'xxxx'],
    ['password', 'xxxxx']
  ]

当您尝试使用Node连接到本地Oracle XE数据库时,遇到了相同的错误.进行上述更改后,我就可以连接了.我不认为您遇到的错误是RedShift特有的-我认为它会影响所有数据库.

I got the same error as you attempting to use Node to connect to a local Oracle XE database. After making the change above I was able to connect. I don't believe the error you are getting is specific to RedShift - I believe it affects all databases.

请注意,以上属性必须指定为2元素数组的数组.如下所示的对象似乎是指定属性的明显方法,但是它不起作用:

Note that the properties above have to be specified as an array of 2-element arrays. An object such as the following would seem the obvious way to specify the properties, but it doesn't work:

  // Don't do this, it doesn't work.
  properties: {
    user: 'xxxx',
    password: 'xxxxx'
  }

说实话,我上面提出的解决方案是一种解决方法.我只能通过阅读jdbc模块的源代码来找到它.我不能说这个模块给我留下了深刻的印象,文档中给出的示例代码不起作用,以及用于指定自定义属性的某种违反直觉和未记录格式的东西.

To be honest, the fix I've proposed above is a workaround. I only found it by reading the source of the jdbc module. I can't say I'm terribly impressed with this module, what with the example code given in the documentation not working, and with a somewhat counter-intuitive and undocumented format for specifying custom properties.

这篇关于从节点jdbc进行Redshift数据访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆