Closed thmoeller closed 10 years ago
Can you post some example code that is generating the error?
This is the module code. It executes correct until jdbc.close() is called:
jdbc = require('../../nodejs/node_modules/jdbc/index');
var path = require('path'); // For crossplatform compatibility of path values
var mysqlrequest = function (input, callback) {
console.log("Start DB request");
//Create connection string
var conurl = 'jdbc:mysql://' + input.host + ':' + input.port + '/' + input.database + '?user=' + input.user + '&password=' + input.pass;
//Create connection configuration
var config = {
libpath: path.resolve('dbdrivers/mysql-connector-java-5.1.30-bin.jar'),
drivername: 'com.mysql.jdbc.Driver',
url: conurl
};
//Initialize Connection with given config
jdbc.initialize(config, function(err, res) {
if (err) callback(err, null);
});
//Create a QueryHandler to return results
var genericQueryHandler = function(err, results) {
console.log("Return result");
if (err) {
//console.log(err);
callback(err, null);
} else if (results) {
//console.log(results);
jdbc.close();
callback(null, results);
}
};
//Establish Connection to database and execute defined query
jdbc.open(function(err, conn) {
if (conn) {
// SELECT statements are called with executeQuery
jdbc.executeQuery(input.statement, genericQueryHandler);
}
if (err) {
callback(err, null);
}
}); //End jdbc.open
jdbc.close();
}; // End mysqlrequest
exports.request = mysqlrequest;
Cheers
Thorsten
OK, wrong button, still open
Sorry
jdbc.close requires a callback, similar to the open function.
Try
jdbc.close(function(err) {
// err is null if the close was successful
});
The docs in README.md are incorrect at the moment, I'll update those to reflect the close API properly.
@thmoeller what's with line 1 of your example code? That doesn't seem like the right way to require() the module.
Yes, callback in close function did the job.
And yes neurotech, you were right. First line was incorrect, too
Thanks all for your help
Hi,
tried your code and works like a charm standing alone. I put in in a module with callback functionality. This works up to the point, when jdbc.close() is called.
It always fails with:
I tried to put the close somewhere else in the code, but always with the same result.
Any idea??
Thorsten