无法使用JDBC(Node.js)访问点火数据库的元数据?

时间:2018-07-04 13:45:50

标签: javascript node.js jdbc ignite

我正在尝试访问我的元数据,以便使用这两种方法列出我的ignite数据库中的表,但是我所能获得的只是我的模式名称,而没有getmetadata方法中的任何内容,为此正在使用以下代码:

var JDBC = require('jdbc');
var metadata = require('jdbc-metadata');
var async = require("async");
var jinst = require('jdbc/lib/jinst');
var ResultSet = require('jdbc/lib/resultset');
var databasemetadata = require('jdbc/lib/databasemetadata');

if (!jinst.isJvmCreated()) {
  jinst.addOption("-Xrs");
  jinst.setupClasspath([appRoot2 + '/ignite-core-2.4.0.jar']);
}

var config = {
  // Ignite configuration to your server
  url: 'jdbc:ignite:thin://host:port',
  drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
  minpoolsize: 1,
  maxpoolsize: 100,
  properties: {}
};

var igniteConn = new JDBC(config);
igniteConn.initialize(function(err) {
  if (err) {
    done(err);
    return console.error('Connection Error: ' + err);
    saveToLog(req, 'Error on connection: ' + err, 300, 'JO-002', '');
  } else {
    console.log("connection established");
  }
});

igniteConn.reserve(function(err, connObj) {
      if (connObj) {
        console.log("Using connection: " + connObj.uuid);
        var conn = connObj.conn;
        async.series([

          function(callback) {
            conn.getSchema(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log(res);
                callback(res);
              }
            });
          },
          function(callback) {
            conn.getMetadata(function(err, res) {
              if (err) {
                callback(err);
              } else {
                console.log("///////");
                console.log(res);
                callback(res);
              }
            });
          }
        ], function(err, results) {
          // Check for errors if need be.
          // results is an array.
        });

使用driverManager的第二种方法:

var drivermanager = require('jdbc/lib/drivermanager');
drivermanager.getConnection(config.url, null, null, function(err, conn) {
  if (err) throw err;
  testconn = new Connection(conn);

  if (testconn) {
    async.series([
      function(callback) {
        testconn.getMetaData(function(err, result) {
          if (err) callback(err);
          console.log(result);
          /*
          else {
            result.getTables(null,null,null,null,function(err,res){
              if(err) callback(err);

              else {                      
                console.log(res);
              }

            });
          }*/
          //resultSet = result.getTables(null, null, null,"TABLE");
        });
      },
    ], function(err, results) {
      // Results can also be processed here.
      // Release the connection back to the pool.
    });
  }
});

我可以正常地对表运行查询以获取信息。如果有人有任何建议,我将如何获取我的元数据,或者如果有其他选择(例如SELECT information.tabels ...但这无法在点火上运行),我将如何运行该查询来获取元数据非常感谢。

1 个答案:

答案 0 :(得分:2)

以下代码段对我有用:

var config = {
  libpath: 'ignite-core-2.4.0.jar',
  // Ignite configuration to your server
  url: 'jdbc:ignite:thin://127.0.0.1',
  drivername: 'org.apache.ignite.IgniteJdbcThinDriver',
  minpoolsize: 1,
  maxpoolsize: 100,
  properties: {}
};

var jdbcMetadata = new metadata(config);

jdbcMetadata.metadata(function (err, metadata) {
    console.log('Getting tables...');

    jdbcMetadata.tables({schema: "PUBLIC", types: ['TABLE', 'VIEW']}, function (err, tables) {
        console.log(tables);

        jdbcMetadata.close(function(err) {
          console.log('Connection closed');
        });
    });
});

我可以看到:

[ { tableCat: null,
    tableSchem: 'PUBLIC',
    tableName: 'A',
    tableType: 'TABLE',
    remarks: null,
    typeCat: null,
    typeSchem: null,
    typeName: null,
    selfReferencingColName: null,
    refGeneration: null } ]