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 Object Relational Mapping and the fly likes com.mysql.jdbc.CommunicationsException 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 » Object Relational Mapping
Bookmark "com.mysql.jdbc.CommunicationsException" Watch "com.mysql.jdbc.CommunicationsException" New topic
Author

com.mysql.jdbc.CommunicationsException

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I am using mysql database with a Hibernate application. Sometimes it works , but sometime, it throws following exception



What is the reason behind this?


kunal
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
strange sometimes work , sometimes doesnt ??

few questions for you
  • are you facing a similar issue when trying to to connect to the DataBase using a query browser ? ( like sql developer for oracle or Toad ?? ) if yes its sporadic some network error
  • if NOT , try to change your connection properties server name with ip address etc (ex : localhost with the ip address i,e 127.0.0.1 or computer name)


  • lavnish.blogspot.com
    Kunal Lakhani
    Ranch Hand

    Joined: Jun 05, 2010
    Posts: 622
    Thanks for your reply
    When i login through console or phpadmin, it opens successfully

    I need to change the connection properties in my hibernate cfg.xml?
    lavnish lalchandani
    Ranch Hand

    Joined: Feb 28, 2007
    Posts: 79
    yes, try changing the server name to ip address ( or vice versa )
    also, does PHPAdmin always works ??
    Kunal Lakhani
    Ranch Hand

    Joined: Jun 05, 2010
    Posts: 622
    Yes, phpmyadmin always works

    This is the change i have done
    <property name="connection.url">jdbc:mysql://127.0.0.1:3306/smartlife</property>

    But it gives the same exception

    Is my url correct?

    lavnish lalchandani
    Ranch Hand

    Joined: Feb 28, 2007
    Posts: 79
    possibly last thing i can think of is
    * may be a firewall issue
    * may be you can try changing the port of MySQL ( as of now you are using default 3306)
    Kunal Lakhani
    Ranch Hand

    Joined: Jun 05, 2010
    Posts: 622
    Thanks for your reply lavnish lalchandani
    Trying changing the port
    Kunal Lakhani
    Ranch Hand

    Joined: Jun 05, 2010
    Posts: 622
    Sorry for late response, but, now, i have found out, when this error occurs.
    I am using mysql as the db.

    Here is my hibernate.cfg.xml


    My database name is "smart". Now, when i open the mysql console, it asks for password, which by default is null. I press enter, and then use this command. "use smarts"
    It gets me to smarts db.

    The problem is that, when i have started all services of "WAMPSERVER", (regardless of mysql console) the error never occurs. Only when there is no WAMPSERVER working, the error occurs.
    Also, when i type "127.0.0.1" in browser, it opens the WampServer. Same is the case when i type "localhost" in the browser and press enter. Is that something i need to notice?
    Should i go for separate ,mysql installation?
    What is the problem, and how can i solve it?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: com.mysql.jdbc.CommunicationsException
     
    Similar Threads
    Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
    java.net.ConnectException: Connection refused: connect
    connection to remote mysql db
    url recorder
    MySQL 4.1 [java.net.ConnectException: Connection refused]