aspose file tools*
The moose likes JDBC and the fly likes Connect to a dataserver instead of a DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Connect to a dataserver instead of a DB" Watch "Connect to a dataserver instead of a DB" New topic
Author

Connect to a dataserver instead of a DB

Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
All,

When defining the connection, isn't it possible to connect to a dataserver instead of a DB thus:

conn =
DriverManager.getConnection("jdbc:mysql://host:port/" +
"user=user&password=password");
(This is from my own code).
The above fails.

conn =
DriverManager.getConnection("jdbc:mysql://hhost:port/myDB?" +
"user=user&password=password");

The above works fine and connects to myDB.
The reason is that I need to run queries running across multiple DBs within the same server.

Thanks,
Sashi
sathish kumar
Ranch Hand

Joined: Feb 14, 2007
Posts: 47
You would want to re-think if you want to really connect two databases using one connection object.
Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
I don't see why not.

Let's say you're logged into a DB via a CLI. Wouldn't you like to be able to execute a query across DB's and fetch the results?

I'm likening a JDBC Connection object to a manual connection established as above, via a CLI or GUI. You should still be able to run such a query.

However, I think my initial question was not well stated. If I'm logged into a DB server with a certain ID, whether or not I can access other DBs will depend on access permissions for the same ID. In case of no conflict, the same connection can be used to access different DBs without problems.

The JDBC connection object seems to work the same way (after some experimenting on my part).

I don't think there is such a thing as "connecting to a dataserver". You connect to a DB and depending on your access permissions, you will be able to access the other DBs on the same server.

I guess I answered my own question.
sathish kumar
Ranch Hand

Joined: Feb 14, 2007
Posts: 47
Let's say you're logged into a DB via a CLI. Wouldn't you like to be able to execute a query across DB's and fetch the results?


Of course this is perfectly true. You can re-use one connection to connect to various same type of database.
My point being, when you are having one connection object and when you toggle between databases then it will be a maint. nightmare. My thought is you hold separate connection object for each database.
 
Don't get me started about those stupid light bulbs.
 
subject: Connect to a dataserver instead of a DB