node.js - Cannot connect my nodejs to mysql -


my code below

    var jdbc = require('jdbc'); var jinst = require('jdbc/lib/jinst'); var pool = require('jdbc/lib/pool');   // isjvmcreated true after first java call.  when happens, // options , classpath cannot adjusted. if (!jinst.isjvmcreated()) {     // add java options required project here.  1 chance     // setup options before first java call.     jinst.addoption("-xrs");     // add jar files required project here.  1 chance     // setup classpath before first java call.     jinst.setupclasspath(['./jars/mysql-connector-java-5.1.38-bin.jar']); } var mysql = new jdbc({     url: 'jdbc:mysql://localhost:3306/nodejs',     drivername: 'com.mysql.jdbc.driver',     minpoolsize: 5,     maxpoolsize: 10,     user: 'root',     password: 'root' }); mysql.initialize(function(err) {     if (err) {         console.log(err);     } }); 

i have jar in folder , mysql running in local. getting following error

    java.lang.noclassdeffounderror: com/mysql/jdbc/driver caused by: java.lang.classnotfoundexception: com.mysql.jdbc.driver     @ java.net.urlclassloader.findclass(unknown source)     @ java.lang.classloader.loadclass(unknown source)     @ sun.misc.launcher$appclassloader.loadclass(unknown source)     @ java.lang.classloader.loadclass(unknown source) ] cause: nodejava_java_lang_noclassdeffounderror {} } { [error: error running static method java.sql.sqlexception: no suitable driver found jdbc:mysql://localhost:3306/nodejs     @ java.sql.drivermanager.getconnection(unknown source)     @ java.sql.drivermanager.getconnection(unknown source)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     @ java.lang.reflect.method.invoke(unknown source) ] cause: nodejava_java_sql_sqlexception {} } 

please help. there initialisation commands neede in nodejs?

i tried code , works, think path setupclasspath() not good. try using absolute path, relative path works if working directory set expect:

if (!jinst.isjvmcreated()) {     jinst.addoption("-xrs");     jinst.setupclasspath([__dirname + '/jars/mysql-connector-java-5.1.38-bin.jar']); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -