# java.lang.NoClassDefFoundError trying to connect an external database

**URL:** <https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894>\
**Category:** Ignition\
**Tags:** scripting, database\
**Created:** [October 21, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894 "2020-10-21T19:53:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gema.corbi](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@gema.corbi](https://forum.inductiveautomation.com/u/gema.corbi)\
**Post date:** [October 21, 2020, 7:53pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/1 "2020-10-21T19:53:08Z")

</div>

Hi everyone!

I’m trying to connect with a database from a script at the Script Console, using the following code:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/6/5667efe5d177d4daab1a31813c45bdf0a7517d3f.png)

It makes a connection with a MS SQL Server database through the zxJDBC library and it should return the database version. Instead of this, I obtain the following error message:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/0/b03a16143abd9cc55ba04975e35eaa6a162e63e5.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/5/e527af6863b4fa8475e3f90222905f64052d94f0.png)

Does anyone know what could be causing this error?  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 21, 2020, 8:24pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/2 "2020-10-21T20:24:45Z")

</div>

JAXB was removed in Java 11 (see: [JEP 320](http://openjdk.java.net/jeps/320)). How are you providing an MSSQL driver to the designer/client scope? It’s likely an old version that doesn’t support Java 11.

That said - _why_ are you trying to dynamically create database connections from the runtime? This seems like a bad idea.

---

<div class="post-metadata">

**Author:** ![gema.corbi](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@gema.corbi](https://forum.inductiveautomation.com/u/gema.corbi)\
**Post date:** [October 22, 2020, 5:55pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/3 "2020-10-22T17:55:38Z")

</div>

I have copied the JAR file containing the driver at the folder _C:\Program Files\Inductive Automation\Ignition\lib\core\common_, where the zxJDBC library can find it. I’m using this method because I want to connect to databases in other computers without the needing of configurate a new connection in Ignition. The zxJDBC library can connect to different database types using different drivers. A friend of mine has tried the same script in his Ignition and it worked, so probably the error could be caused by missing libraries. Is there some way to add JAXB to Ignition?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 22, 2020, 6:10pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/4 "2020-10-22T18:10:15Z")

</div>

No, and it’s the wrong solution anyways. Download the latest MSSQL driver, from Microsoft directly, and do the same shenanigans with the JAR file. That’ll _probably_ work.

That said, this is all unsupported, so you’re very much on your own if something goes wrong.

---

<div class="post-metadata">

**Author:** ![gema.corbi](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@gema.corbi](https://forum.inductiveautomation.com/u/gema.corbi)\
**Post date:** [October 22, 2020, 6:31pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/5 "2020-10-22T18:31:40Z")

</div>

So, if all this is unsupported in Java 11, what is the common way to access to external databases directly from the script? Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 22, 2020, 8:19pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/6 "2020-10-22T20:19:30Z")

</div>

> [@gema.corbi](#):
>
> common way to access to external databases directly from the script?

The supported way in Ignition is to define database connections in the gateway and run all of your DB operations with the documented `system.db.*` script functions.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 22, 2020, 8:19pm UTC](https://forum.inductiveautomation.com/t/java-lang-noclassdeffounderror-trying-to-connect-an-external-database/39894/7 "2020-10-22T20:19:45Z")

</div>

There _is_ no supported way to do so. The supported way is to make database connections on the gateway, using the database connection mechanism.

And, to clarify - the only part of this that’s related to Java 11 is that _whatever version of the MSSQL JDBC driver you are using_ has an implicit dependency on JAXB, which is no longer bundled with the standard Java Runtime as of Java 11. If you download a _new_ version of the MSSQL driver (it’s freely available: [https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15](https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15)) _that works on Java 11_ then I would expect the driver to work in this specific scenario.

The aspect that is unsupported is unsupported from Inductive Automation’s perspective. We have exactly one established mechanism to create database connections - do anything else, and you’re on your own.
