So anyways I have a java program like this and it totally works.
1 import java.sql.*;
2 import org.netezza.*;
class Conn {
public static void main (String args []) throws SQLException {
6 try{Class.forName ("org.netezza.Driver");
7 }
8 catch (ClassNotFoundException e) {
9 System.out.println("You made it to here");
10 e.printStackTrace();
11 }
12
13 Connection conn = DriverManager.getConnection("jdbc:netezza://server/dbname", "user", "pass");
14
15 Statement stmt = conn.createStatement();
16 ResultSet rset = stmt.executeQuery("SELECT 'foo'");
17 while (rset.next()){
18 System.out.println(rset.getString(1));
19 }
20 stmt.close();
21 conn.close();
22 }
23 }
However, when I attempt to follow what seems like every vanilla JDBC + Jruby tutorial on the internet I get the ubiquitous error "NativeException: java.sql.SQLException: No suitable driver" with this code.
1 require 'java'
2 require 'jruby'
3 require 'nzjdbc.jar'
4 #F = java.io.File
5 #class_loader = JRuby.runtime.jruby_class_loader
6 #class_loader.add_url(F.new('path').to_url)
7 #class_loader.add_url(F.new('nzjdbc.jar').to_url)
8
9 include_class "java.sql.DriverManager"
10 include_class "org.netezza.Driver"
11
12 p $CLASSPATH
13 p $LOAD_PATH
14
15 server = 'server'
16 databaseName = 'dbname'
17 user = 'user'
18 pass = 'pass'
19
20 p DRVRMAN = org.netezza.Driver.new
21
22 begin
23 #clazz = Java::JavaClass.for_name("org.netezza.Driver")
24 clazz = java.lang.Class.for_name("org.netezza.Driver", true, JRuby.runtime.jruby_class_loader)
25 #java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
26 #java.sql.DriverManager.registerDriver(Java::OrgNetezza::Driver.new)
27 url = "jdbc:netezza://" + server + "/" + databaseName
28 p url
29 conn = DriverManager.getConnection(url, user, pass)
30 stmt = conn.create_statement
31 rs = stmt.execute_query("SELECT 2 + 2")
32
33 while rs.next
34 p [rs.get_int(1)]
35 end
36 ensure
37 rs.close rescue nil
38 stmt.close rescue nil
39 conn.close rescue nil
40 end
and I have tried what seems like everything I could find to fix this issue including checking out the activerecord-jdbc and dbi-jdbc implementations. Its very frustrating and I guess I don't really understand whats going on besides having an issue with teh classloader, load path and the Classpath. Anyways, I was hoping someone could explain step by step how the DriverManager registers drivers in Java and why the java code totally succeeds while the ruby code (which seems equivalent) does not as well as help me mitigate these errors.
(Also any "install X gem" won't work in this instance as a large deal of bureaucracy must be overcome for anything new to be allowed into this system)