GeeCON Prague 2014*
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


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Statement" Watch "JDBC Statement" New topic
Author

JDBC Statement

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 321

Hello,
Is the below statement right :

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

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

newConnection1
User:Root Host :127.0.0.1:3307

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

Please advise.

Thank you.

Thanks,
Pramod
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2501
    
    8

If your computer works fine, localhost is the same as 127.0.0.1

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

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

ping 127.0.0.1


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: 321

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: 321

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

MySQL's default port is 3306, not 3307.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JDBC Statement