i want get a connection to a PostgreSQL database then i wrote a JRuby
script :
1 require 'java’
2 module JavaLang
3 include_package "java.lang"
4 end
5 module JavaSQL
6 include_package "java.sql"
7 end
8
9 JavaLang::Class.forName(“org.postgresql.Driver”)
10 […]
this raises an error :
connect2macave.rb:9: Undefined method ‘forName’ for Class:Class
(NameError)
from connect2macave.rb:9
i don’t understand this error because this script is similar to java
version :
import java.sql.*;
import javax.swing.JOptionPane;
public class connect2macave {
public static void main(java.lang.String[] args) {
ResultSet bouteilles = null;
Statement query = null;
Connection pSQL = null;
try {
// Here we load the JDBC driver.
Class.forName(“org.postgresql.Driver”);
which works well…
···
from :0
–
yt
— Yvon Thoraval yvon.thoravalNO-SPAM@free.fr wrote:
i want get a connection to a PostgreSQL database then i wrote a JRuby
script :
[—]
9 JavaLang::Class.forName(“org.postgresql.Driver”)
I think the “Class” constant here will refer to Ruby’s Class, not
Java’s. You’ll have to use an alias for that constant.
/Anders
···
=====
Anders Bengtsson ndrsbngtssn@yahoo.se
Stockholm, Sweden
Höstrusk och grå moln - köp en resa till solen på Yahoo! Resor på adressen http://se.docs.yahoo.com/travel/index.html
i want get a connection to a PostgreSQL database then i wrote a JRuby
script :
[—]
9 JavaLang::Class.forName(“org.postgresql.Driver”)
I think the “Class” constant here will refer to Ruby’s Class, not
Java’s. You’ll have to use an alias for that constant.
tanxs for your answer, i did some progress in the meantime
pgd = Java::JavaClass.for_name(“org.postgresql.Driver”)
then replacing forName by for_name works…
pSQL = JavaSQL::DriverManager.getConnection(“jdbc:postgresql:macave”,
“postgresql”, “yvon5533”)
right now, i"m stuck with the above line raising a “run time” error :
(eval):4:in ‘getConnection’: Native Exception: ‘class
java.sql.SQLException’; Message: No suitable driver; StackTrace:
java.sql.SQLException: No suitable driver (RuntimeError)
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jruby.javasupport.JavaMethod.invokeWithExceptionHandling(JavaMethod.
java:148)
at
org.jruby.javasupport.JavaMethod.invoke_static(JavaMethod.java:135)
at
org.jruby.javasupport.JavaMethod.callIndexed(JavaMethod.java:197)
at
org.jruby.runtime.IndexedCallback.execute(IndexedCallback.java:72)
at
org.jruby.internal.runtime.methods.CallbackMethod.call(CallbackMethod.ja
va:63)
at org.jruby.RubyModule.call0(RubyModule.java:758)
at org.jruby.RubyModule.call(RubyModule.java:719)
at
org.jruby.evaluator.EvaluateVisitor.visitCallNode(EvaluateVisitor.java:
427)
at org.jruby.ast.CallNode.accept(CallNode.java:64)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitLocalAsgnNode(EvaluateVisitor.j
ava:934)
at org.jruby.ast.LocalAsgnNode.accept(LocalAsgnNode.java:57)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitNewlineNode(EvaluateVisitor.jav
at org.jruby.ast.NewlineNode.accept(NewlineNode.java:65)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitBlockNode(EvaluateVisitor.java:
323)
at org.jruby.ast.BlockNode.accept(BlockNode.java:89)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at org.jruby.RubyObject.eval(RubyObject.java:362)
at
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java
:73)
at org.jruby.RubyModule.call0(RubyModule.java:758)
at org.jruby.RubyModule.call(RubyModule.java:719)
at
org.jruby.evaluator.EvaluateVisitor.visitCallNode(EvaluateVisitor.java:
427)
at org.jruby.ast.CallNode.accept(CallNode.java:64)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitLocalAsgnNode(EvaluateVisitor.j
ava:934)
at org.jruby.ast.LocalAsgnNode.accept(LocalAsgnNode.java:57)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitNewlineNode(EvaluateVisitor.jav
at org.jruby.ast.NewlineNode.accept(NewlineNode.java:65)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at
org.jruby.evaluator.EvaluateVisitor.visitBlockNode(EvaluateVisitor.java:
323)
at org.jruby.ast.BlockNode.accept(BlockNode.java:89)
at
org.jruby.evaluator.EvaluateVisitor.eval(EvaluateVisitor.java:218)
at org.jruby.runtime.ThreadContext.eval(ThreadContext.java:116)
at org.jruby.Ruby.eval(Ruby.java:243)
at org.jruby.Main.runInterpreter(Main.java:122)
at org.jruby.Main.main(Main.java:89)
from (eval):4:in 'getConnection'
from connect2macave.rb:11
···
Le 5 mars 04, à 14:01, Anders Bengtsson a écrit :
— Yvon Thoraval yvon.thoravalNO-SPAM@free.fr wrote:
a:39)
a:1020)
a:1020)
from :0