guitard00d123
guitard00d123

Reputation: 367

IBM DB2 - Finding where my database is hosted for JDBC connection?

If I create a database in the db2 console (create database CONNTEST), where will the database be hosted? I know that my instance is pointing to localhost:50000, but in my JDBC application con = DriverManager.getConnection (url, user, password); where url = jdbc:db2://localhost:50000/CONNTEST is returning an invalid database address error. Is there a way to see where my database is hosted from the db2 console itself? Thanks!

Upvotes: 0

Views: 3521

Answers (2)

bhamby
bhamby

Reputation: 15450

If you can run the db2 command line, you can figure out how the database is cataloged, and work your way back to the host address. I'm assuming that your database is not a mainframe database... that adds some complexity to the directory that I won't go over.

First, you'll run db2 list database directory, and you'll get some output like this:

Database 1 entry:

 Database alias                       = DB1
 Database name                        = DB1
 Node name                            = DB1
 Database release level               = 14.00
 Comment                              =
 Directory entry type                 = Remote
 Catalog database partition number    = -1
 Alternate server hostname            =
 Alternate server port number         =

The database alias field will be your CONNTEST name that you've been connecting to. You want to know what the node name field is. The database name field could be different, that field will be what the database is actually called on the server side.

Taking the node name, you will run db2 list node directory. You'll look for the node entry that matches the node name from your database entry:

Node 1 entry:

 Node name                      = DB1
 Comment                        =
 Directory entry type           = LOCAL
 Protocol                       = TCPIP
 Hostname                       = db2host.domain.local
 Service name                   = 50000

Here, you'll see the hostname and service name fields, which give you the host and port that it is connecting to.

Upvotes: 2

duffymo
duffymo

Reputation: 308763

It might be that localhost isn't being mapped to your IP address OR 127.0.0.1. You can start by trying your machine's IP address.

Make sure your DB2 instance is listening on port 50000. That's the default, but it's worth checking.

If that doesn't work, perhaps it's a permission issue. The database itself might be restricting access by client IP, username, and password. That's how it works with MySQL, for example.

Upvotes: 0

Related Questions