【问题标题】:Redshift data access from node jdbc从节点 jdbc 访问 Redshift 数据
【发布时间】:2015-11-07 05:28:18
【问题描述】:

当我尝试使用下面提到的代码从 redshift 中获取数据时出现以下错误

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 是否存在问题?

【问题讨论】:

    标签: node.js jdbc amazon-redshift


    【解决方案1】:

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

    尝试替换配置中的两行

      user: 'xxxx',
      password: 'xxxxx'
    

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

    我遇到了与您尝试使用 Node 连接到本地 Oracle XE 数据库相同的错误。进行上述更改后,我能够连接。我不相信您遇到的错误特定于 RedShift - 我相信它会影响所有数据库。

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

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

    说实话,我上面提出的解决方法是一种解决方法。我只是通过阅读 jdbc 模块的源代码才找到的。我不能说我对这个模块印象深刻,文档中给出的示例代码不起作用,并且指定自定义属性的格式有点违反直觉和未记录。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多