Class.forName class not found exception

require ‘java’
module JavaLang
include_package ‘java.lang’
end

module JavaSql
include_package ‘java.sql’
end

JavaLang::Class.forName(“com.mysql.jdbc.Driver”).newInstance

.
.
.

This is the code that i tried in jruby(Netbeans IDE).

But i am getting class not found exception.(Class.forName). Can anybody
help me for this…

Hah, looks like you found the example I posted on your own :slight_smile: Answers
below…

On Wed, Mar 3, 2010 at 3:38 AM, Anbu S. [email protected]
wrote:

require ‘java’
module JavaLang
 include_package ‘java.lang’
end

remove this; it’s not needed

module JavaSql
 include_package ‘java.sql’
end

JavaLang::Class.forName(“com.mysql.jdbc.Driver”).newInstance

replace with

com.mysql.jdbc.Driver.new

This is the code that i tried in jruby(Netbeans IDE).

But i am getting class not found exception.(Class.forName). Can anybody
help me for this…

You probably don’t have the MySQL jar anywhere in classpath. You can
get it either by downloading (google for “mysql jdbc driver”) or by
installing the jdbc-mysql gem:

~/projects/jruby âž” gem install jdbc-mysql
Successfully installed jdbc-mysql-5.0.4
1 gem installed
Installing ri documentation for jdbc-mysql-5.0.4…
Installing RDoc documentation for jdbc-mysql-5.0.4…

~/projects/jruby âž” jruby -rjava -rubygems -e “require ‘jdbc/mysql’;
require ‘java’; puts com.mysql.jdbc.Driver.new”
com.mysql.jdbc.Driver@10cec16

~/projects/jruby âž”
CLASSPATH=lib/ruby/gems/1.8/gems/jdbc-mysql-5.0.4/lib/mysql-connector-java-5.0.4-bin.jar
jruby -rjava -e “puts com.mysql.jdbc.Driver.new”
com.mysql.jdbc.Driver@c9b196

The last command line is basically how you’d use the downloaded MySQL
JDBC jar, too.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email