JuliaDatabases / JDBC.jl

Julia interface to Java database drivers
Other
38 stars 19 forks source link

IllegalMonitorStateException on connection to Netezza DB #50

Open metanoid opened 5 years ago

metanoid commented 5 years ago

I'm trying to extract data from a Netezza database.

I run the following:

using JavaCall
JavaCall.addClassPath("C:/JDBC/nzjdbc.jar")
using JDBC
JDBC.usedriver("C:/JDBC/nzjdbc.jar")
JDBC.init()
classforname("org.netezza.Driver")
hostname = "hostname"
port = "5480"
database = "db"
connectionstring = "jdbc:netezza://$(hostname):$(port)/$(database);user=$(ENV["netezza_user"]);password=$(ENV["netezza_pwd"])"
conn = JDBC.DriverManager.getConnection(connectionstring)

I get the following error:

JavaCall.JavaCallError("Error calling Java: java.lang.IllegalMonitorStateException")
in top-level scope at base\none
in getConnection at JDBC\yjpfX\src\JDBC.jl:19
in jcall at JavaCall\toamy\src\core.jl:143
in _jcall at JavaCall\toamy\src\core.jl:247
in geterror at JavaCall\toamy\src\core.jl:274 
in geterror at JavaCall\toamy\src\core.jl:294

I don't know why this is happening, and can't find clues in the documentation

aviks commented 5 years ago

Not sure what is happening here? What version of Java are you using? If you write similar code in Java directly, does it work?

metanoid commented 5 years ago

I have:

java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)

I can try figure out similiar java code, but I'm no expert. Could you provide an example java code snippet that I could use as a template?

metanoid commented 5 years ago

This essentially equivalent code works in R on the same machine.

library(RJDBC)

drv = JDBC(driverClass = "org.netezza.Driver",
           classPath = "C:/JDBC/nzjdbc.jar")
conn = dbConnect(drv, paste0("jdbc:netezza://DCP:5480/db;user=",username,";password=",pwd))
dbListTables(conn)
a = dbGetQuery(conn, "SELECT *
  FROM H_OD.HS_CM.HE_ATT
               limit 100")
aviks commented 5 years ago

And which version of Julia? Also, is a Java stack trace printed at all?

The trouble is, I do not have access to a netezza database, and even the driver is not freely downloadable.

metanoid commented 5 years ago

Unfortunately no Java stack trace is shown - maybe there's a way to make Java more verbose?

julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\Users\colin37\AppData\Local\JuliaPro-1.2.0-1\app-1.40.1\atom.exe"  -a
  JULIA_NUM_THREADS = 4
aviks commented 5 years ago

Ah could you please try with Julia 1.0.x? There are some issues with threading and Julia 1.1/1.2

metanoid commented 5 years ago

Ah could you please try with Julia 1.0.x? There are some issues with threading and Julia 1.1/1.2

Julia 1.0.5 (LTS) works for the above - thanks!

metanoid commented 4 years ago

Testing on Julia 1.3.0, and this is still an issue. Error message seems more informative now?

julia> cnxn = JDBC.Connection("jdbc:oracle:thin:@$(hostname):$(port)/$(service_name)", props = Dict("user" => ENV["oracle_user"], "password" => ENV["oracle_pwd"]))
Exception in thread "main" ERROR: JavaCall.JavaCallError("Error calling Java: java.lang.NoClassDefFoundError: Could not initialize class oracle.jdbc.driver.T4CDriverExtension")
Stacktrace:
 [1] geterror(::Bool) at C:\Users\username\.julia\packages\JavaCall\Iz2MQ\src\core.jl:294
 [2] geterror at C:\Users\username\.julia\packages\JavaCall\Iz2MQ\src\core.jl:274 [inlined]
 [3] _jcall(::JavaMetaClass{Symbol("java.sql.DriverManager")}, ::Ptr{Nothing}, ::Ptr{Nothing}, ::Type, ::Tuple{DataType,DataType}, ::String, ::Vararg{Any,N} where N) at C:\Users\username\.julia\packages\JavaCall\Iz2MQ\src\core.jl:247
 [4] jcall(::Type{JavaObject{Symbol("java.sql.DriverManager")}}, ::String, ::Type, ::Tuple{DataType,DataType}, ::String, ::Vararg{Any,N} where N) at C:\Users\username\.julia\packages\JavaCall\Iz2MQ\src\core.jl:143
 [5] getConnection(::String, ::Dict{String,String}) at C:\Users\username\.julia\packages\JDBC\2ruzk\src\JDBC.jl:23
 [6] #Connection#1(::Dict{String,String}, ::String, ::Type{JDBC.Connection}, ::String) at C:\Users\username\.julia\packages\JDBC\2ruzk\src\interface.jl:50
 [7] (::Core.var"#kw#Type")(::NamedTuple{(:props,),Tuple{Dict{String,String}}}, ::Type{JDBC.Connection}, ::String) at .\none:0
 [8] top-level scope at none:0
mkitti commented 4 years ago

I guess the question is whether oracle.jdbc.driver.T4CDriverExtension is on your classpath. If it is, is there another class that it depends on which is not? How did you set your classpath?