# JuliaPro JDBC.destroy() not working

**URL:** <https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645>\
**Category:** Tooling\
**Tags:** juliapro\
**Created:** [April 15, 2020, 2:24pm UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645 "2020-04-15T14:24:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [April 15, 2020, 2:24pm UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/1 "2020-04-15T14:24:37Z")

</div>

I am trying to use JDBC in the JuliaPro IDE, but it doesn’t seem to release the JMV from memory when the destroy() method is called. If I run the following code twice, then I get an error, but shouldn’t it work if destroy() released the JVM from memory?

Code:

```julia
using JDBC
JDBC.init()
JDBC.destroy()

```

Error:

```julia
ERROR: LoadError: JavaCall.JavaCallError("Unable to initialise Java VM: -1")
Stacktrace:
 [1] init(::OrderedCollections.OrderedSet{String}) at C:\Users\dburch\.juliapro\JuliaPro_v1.0.5-2\packages\JavaCall\0wJQZ\src\jvm.jl:180
 [2] init() at C:\Users\dburch\.juliapro\JuliaPro_v1.0.5-2\packages\JavaCall\0wJQZ\src\jvm.jl:156
 [3] init() at C:\Users\dburch\.juliapro\JuliaPro_v1.0.5-2\packages\JDBC\2ruzk\src\JDBC.jl:40
 [4] top-level scope at none:0
in expression starting at untitled-101b06be47b56380518cb53da02cdcaa:2

```

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [April 16, 2020, 9:08am UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/2 "2020-04-16T09:08:34Z")

</div>

Yeah, the JNI unload does not work correctly. I thought I had documented this somewhere, but can’t find it now.

This is one of the reasons why the `init` is not called by default on module load – the user needs to call it explicitly. This allows you to set the required classpath before the JVM loads, since once loaded, you cannot unload it till the process restarts.

Hope this helps.

Avik

---

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [April 16, 2020, 3:21pm UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/3 "2020-04-16T15:21:38Z")

</div>

Does this mean it won’t be possible to use two different drivers at the same time? I was trying to connect through JDBC to both a MySQL and Oracle databases (using two different JDBC drivers). I am able to use JDBC to connect independently, but connecting to both has proved to be fruitless so far.

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [April 17, 2020, 10:07pm UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/4 "2020-04-17T22:07:21Z")

</div>

No, you absolutely can. The trick is to set the classpath with both driver jars before you call `init`. So something like the below:

```julia
using JDBC
JDBC.usedriver("path_to_oracle_driver")
JDBC.usedriver("path_to_mysql_driver")
JDBC.init()

conn1 = DriverManager.getConnection(<oracle connection string>)
conn2 = DriverManager.getConnection (<mysql connection string>)
.....
<use conn and conn2 to make queries and fetch data>
......
close(conn1)
close(conn2)

```

Does this not work for you?

---

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [April 18, 2020, 4:19am UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/5 "2020-04-18T04:19:30Z")

</div>

It worked! Thank you. You made my day/night. If you post this answer to this other post, then I’ll mark it solved: [JDBC 2 Concurrent Connections](https://discourse.julialang.org/t/jdbc-2-concurrent-connections/37608)

The topic on this page is different. I’ll mark your other post as the answer, since it explains what’s happening for posterity and the like.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 12, 2023, 4:41pm UTC](https://discourse.julialang.org/t/juliapro-jdbc-destroy-not-working/37645/6 "2023-09-12T16:41:32Z")

</div>


