• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Statement

 
pramod talekar
Ranch Hand
Posts: 345
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pramod talekar
Ranch Hand
Posts: 345
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 345
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MySQL's default port is 3306, not 3307.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic