Forum Discussion

Kribbstar's avatar
26 days ago

Include external files (XML) for JDBC connection

Hello!
I'm trying to create a new JDBC connection for IBM DL1 database. But the problem is that I need to include some metadata xml which describes the database layout in order for the JDBC connection to work.

The JDBC connection string ends up something like this:
"jdbc:ims://HOSTANAME:PORT/xml://DATABASE"

but when trying it out I get:
"Can't get the Connection for specified properties; java.sql.SQLException: An error occurred accessing the PSB: Metadata XML file for PSB "DATABASE" not found. An xml file named ".xml" must be included in the classpath."

Which means it can't find the xml metadata.

I have included the JDBC driver jar but I have not found a way to include non-jar items into the classpath (things you usually would have in a "resource" folder in a java project).

Anyone know of a way?

  • xeniacanary's avatar
    xeniacanary
    New Contributor

    To include external XML files for a JDBC connection in your Java project, first create an XML file (e.g., db_config.xml) to store database connection details such as URL, username, password, and driver. Then, use Java's DocumentBuilderFactory and DocumentBuilder to parse the XML file, extract these values, and use them to configure the JDBC connection. For example, in your Java code, you can load the XML configuration and retrieve the required information to establish the connection using DriverManager.getConnection(). Additionally, ensure that the appropriate JDBC driver (e.g., MySQL's mysql-connector-java for MySQL databases) is included in your project’s classpath. By doing this, you can manage your database connection configuration externally and keep the code flexible.