0

I have the following code to connect to a Virtuoso 7 Server through Node and JDBC (via jdbc package on npm):

    const checkDatabaseConnection = function(callback)
{
    const JDBC = require('jdbc');
    const jinst = require('jdbc/lib/jinst');

    if (!jinst.isJvmCreated()) {
        jinst.addOption("-Xrs");
        jinst.setupClasspath([
            Pathfinder.absPathInApp("conf/virtuoso-jdbc/virtjdbc4.jar")
        ]);
    }

    const config = {
        // Required
        url : "jdbc:virtuoso://192.168.56.249:1111",
        drivername: 'virtuoso.jdbc4.Driver',
        minpoolsize: 1,
        maxpoolsize: 100,
        maxidle : 5000,
        username : "dba",
        password : "dba",

        properties: {}
    };

    const jdbcdb = new JDBC(config);

    jdbcdb.initialize(function(err) {
        if (err) {
            console.log(err);
        }
    });
};

It immediately returns:

{ Error: Error running static method
virtuoso.jdbc4.VirtuosoException: Virtuoso Communications Link Failure (timeout) : Connection to the server lost
    at virtuoso.jdbc4.VirtuosoFuture.nextResult(VirtuosoFuture.java:63)
    at virtuoso.jdbc4.VirtuosoConnection.connect(VirtuosoConnection.java:328)
    at virtuoso.jdbc4.VirtuosoConnection.connect(VirtuosoConnection.java:224)
    at virtuoso.jdbc4.VirtuosoConnection.<init>(VirtuosoConnection.java:169)
    at virtuoso.jdbc4.Driver.connect(Driver.java:58)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    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:497)
 cause: nodeJava_virtuoso_jdbc4_VirtuosoException {} }

Running Virtuoso JDBC driver 4.2, Virtuoso 7.

I did telnet to the server on the same IP and port, and the server is listening. What could be the problem?

João Rocha da Silva
  • 4,259
  • 4
  • 26
  • 35
  • Please post the full Java exception stacktrace. Likely it simply can't connect because, the server isn't running on 192.168.56.249:1111, or your host is not allowed to connect. – Mark Rotteveel Sep 30 '17 at 08:39
  • I will post the stack trace. Server is listening because it responds to telnet in that port. – João Rocha da Silva Sep 30 '17 at 08:43
  • I added the stack trace. – João Rocha da Silva Sep 30 '17 at 11:51
  • I don't know Virtuoso, but the exception suggests it isn't responding or not finishing the connection handshake. This could still suggest that it isn't Virtuoso listening on port 1111, but something else. – Mark Rotteveel Sep 30 '17 at 11:53
  • Did you run your `telnet` test from the same client environment as where `node.js` is running? Are you running Virtuoso Open Source or Enterprise Edition? Are all components (Virtuoso, JDBC driver, etc.) current/latest version (`java virtuoso.jdbc4.Driver`, `virtuoso-t -?`, `virtuoso-iodbc-t -?`)? – TallTed Sep 30 '17 at 17:30
  • Did you resolve this? If so, what was the issue? If not, can you provide the additional info requested above? – TallTed Oct 19 '17 at 15:46

1 Answers1

1

1) Check the reference node-jdbc The the config property username is wrong, it must me user

2) The next example works properly for me.

var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');
var asyncjs = require('async');

if (!jinst.isJvmCreated()) {
  jinst.addOption("-Xrs");
  jinst.setupClasspath(['./drivers/virtjdbc4.jar']);
}

const config = {
     // Required
     url : "jdbc:virtuoso://192.168.10.101:1111",
     drivername: 'virtuoso.jdbc4.Driver',
     minpoolsize: 1,
     maxpoolsize: 100,
     maxidle : 5000,
     user : "dba",
     password : "dba",

     properties: {}
 };

 const jdbcdb = new JDBC(config);

 jdbcdb.initialize(function(err) {
     if (err) {
         console.log(err);
     }
 });

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

    asyncjs.series([
      function(callback) {
        console.log("call create Statement");

        conn.createStatement(function(err, statement) {
          if (err) {
            callback(err);
          } else {
            console.log("execute query");

            statement.executeQuery("SELECT * FROM Demo.demo.Artist",
                                   function(err, resultset) {
              if (err) {
                callback(err)
              } else {
                resultset.toObjArray(function(err, results) {
                  console.log('res='+JSON.stringify(results));
                  if (results.length > 0) {
                    console.log("Name: " + results[0].Name);
                  }
                  callback(null, resultset);
                });
              }
            });
          }
        });
      }
    ], function(err, results) {
      // Release the connection back to the pool.
      if (err) 
        console.log("Error:"+err);

      jdbcdb.release(connObj, function(err) {
        if (err) {
          console.log(err.message);
        }
      });
    });
  }
});

The output log:

Using connection: f5c60576-1da5-4129-af0a-f25d10160f21
call create Statement
execute query
res=[{"ArtistID":1,"CountryCode":"nl","Name":"Rembrandt Harmenszoon van Rijn"}]
Name: Rembrandt Harmenszoon van Rijn