This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes JDBC Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Statement" Watch "JDBC Statement" New topic

JDBC Statement

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Is the below statement right :

dbcon = DriverManager.getConnection("jdbc:mysql://", "root", "pramod");

I'm using MySQL and it shows the below connection details:

User:Root Host :

or should the above statement be :
dbcon = DriverManager.getConnection("jdbc:mysql://localhost/bookshop", "root", "pramod");

Please advise.

Thank you.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2491

If your computer works fine, localhost is the same as

You can test this by executing these two commands from your command line.:

ping localhost (in windows 7: ping -4 localhost)


Note that you did provide a port number in your first connection string, and not in the second. So your two examples are not completely the same.

Regards, Jan

OCUP UML fundamental and ITIL foundation
youtube channel
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hi Jane,

So should the second statement be localhost:3307 ?

I'm following an example, and only localhost is mentioned in it.

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hi ,

I'm unable to connect to the MySQL db, below is the code :

I get "sorry failed to... " message after execution.

Please advise.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Advice: read the rest of the error message. Better still, print the entire stack trace in that catch-block instead of just the message from the exception.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19655

MySQL's default port is 3306, not 3307.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: JDBC Statement
Similar Threads
How to return ResultSet from Bean to JSP?
Communications link failure
Help needed on Web services
How to make Database Connection in Jsp using sql
how to connect MySql