• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connect to a dataserver instead of a DB

 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would want to re-think if you want to really connect two databases using one connection object.
 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic