aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 316

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

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

Joined: Oct 14, 2005
Posts: 18121
    
    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: 19541
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Statement
 
Similar Threads
Communications link failure
How to return ResultSet from Bean to JSP?
Help needed on Web services
how to connect MySql
How to make Database Connection in Jsp using sql