• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

java.net.ConnectException: Connection refused: connect

 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I have migrated to my vista laptop recently, And I am struggling to connect to Mysql from my Java application. The exception occurs only when I tried to connect to mysql in localhost, where as the same application can connect to mysql server running in other machines.

And I have made sure my user id and passwords are correct, I am able to connect with the same user id/password from command line and not from Java.

Please help me figure out this problem.

Regards
Ananth Chellathurai
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The detailed exception when I connect to my MySQL5.0.67 server with mysql-connector-java-5.1.17 is as follows




and with 3.1.7 is

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to paste the complete code, then only we can figure out where exactly you are going wrong..but the possible solution could be
1)Change the port where your MYSQL listens, the default is 3306 so change it to something else(look for "conf" files where you can change port)

2)See if you can perform the same operation manually
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response. My problem is with only when I tried to connect from a Java application to a database in my local.

I am able to connect tomy local database through command line and through Query browser and the port I used is 3306.

And my code I used to connect to database is a working code, And the same code is able to connect with databases in other machines.

Is it something to do with the environment? Should I have to install 64bit mysql?

Any help on this is greatly appreciated.

Ananth Chellathurai
 
Ananth Chellathurai
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am yet to figure out the issue. I am still not able to connect to my MySQL when I give the host name as localhost. Luckily I had a workaround to give the machine name instead of localhost to connect to MySQL from java.

Hope this helps.

Regards
Ananth Chellathurai
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ananth Chellathurai wrote: Luckily I had a workaround to give the machine name instead of localhost to connect to MySQL from java.

Hope this helps.


Is it a solution you found OR you're asking us ?
And giving machine name, solves your problem, then try giving its IP address, If its local then you know the IP address, 127.0.0.1

And this lines cause the problems,

So providing the code snippet for the same, will be appreciated
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ananth,

I'm also facing the same problem in my Vista. I'm able to connect through the Query Browser but when i try to connect from my java code i get this exception.
Did you find any solution to this problem. Please help me out.. I'm stuck with this issue.

 
Ananth Chellathurai
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of localhost as your host name, try with your machine name.

Ananth Chellathurai
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepa sunder wrote:Hi Ananth,

I'm also facing the same problem in my Vista. I'm able to connect through the Query Browser but when i try to connect from my java code i get this exception.
Did you find any solution to this problem. Please help me out.. I'm stuck with this issue.



Vista comes with a firewall. Have you check this is not what is blocking the connection?
 
Deepa sunder
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ananth.

Fixed the issue. I replaced the localhost with the ip address i,e 127.0.0.1. It started working fine.
I realized that there wasnt any mapping in the host file of vista. Later i mapped the localhost to ip address it started working without any changes in the code.

PS: Vista host file must be changed using the administrative privilege otherwise the changes doesn't reflect.

 
Ananth Chellathurai
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you deepa for the tip.

Ananth Chellathurai
[Ananth's walk on software, Gotchas Rocks]
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the same problem during the last 3 weeks. And since I can only program in Java after my working hours, a week only means about 18 hours to look for the solution. I have searched several forums for the solution but thanks to Joeri Leemans, a Java pro, I looked at this thread.
And changing localhost into 127.0.0.1 was also for me the great breakthrough.
Thanks, guys !
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ananth, Deepa, and Gert:

Thank you, thank you, thank you.

I don't know how you found that out, the difference between localhost and 127.0.0.1, but I've been looking for the answer to this for three or four weeks.

Totally changes my outlook on the day.

Thank you again,

Liam
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic