A Java DB2 JDBC Driver class and URL example

Here's a quick post to help anyone that needs a quick Driver and URL reference when using DB2 with Java and JDBC.

If all you need is a reference to the DB2 JDBC Driver and URL connection string syntax, this basic information should work:

DB2 URL (JDBC Connection) String:

DB2 JDBC Driver String: 

I have used many more parameters when connecting to a DB2 database using Java, JDBC, and Spring, but for a simple Java to DB2 database connection, I think that DB2 Driver and URL information is valid.

A DB2 JDBC Driver and URL database connection example

It may also help to see this used in a simple Java JDBC application. To that end, here's a simple Java JDBC DB2 example that shows how to use the DB2 Driver and URL to establish a database connection.

public class JdbcDb2DriverUrlExample
  public static void main(String[] args)
    Connection connection = null;
      // the db2 driver string
      // the db2 url string
      String url = "jdbc:as400://HOST/DATABASE;";
      // get a db2 database connection
      connection = DriverManager.getConnection(url,"THE_USER", "THE_PASSWORD");
      // now do whatever you want to do with the connection
      // ...
    catch (ClassNotFoundException e)
    catch (SQLException e)

I hope this simple Java/JDBC/DB2 reference is helpful. There are also many other Java, JDBC, and DB2 tutorials on this site. Just use our search form to find many other examples.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.