• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot connect to MySQL server ...  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need some help here. I'm trying to use hibernate with mysql using the tutorial from hibernate source code ( that using hsqldb ). I've change the hibernate.cfg.xml to mysql and when I run it with ant, it shows error likethis :

[java] java.sql.SQLException: Cannot connect to MySQL server on localhost:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.lang.NumberFormatException)

There is no way that my Mysql Server is not running because I check it with Mysql Client tools and it connected normally. And I already placed the mysql connector/j jar in /lib directory. I don't know what's wrong with it. Can somebody help me ?

i'm using hibernate 3.1.3, mysql 5.0.22, mysql-connector-java-3.1.13, mysql-connector-java-3.1.13

and this is my hibernate.cfg.xml :

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"



<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="events/Event.hbm.xml"/>


Ranch Hand
Posts: 662
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Try changing your library with appropriate connector file.
2. Check if any other service is running on port 3306. Could even be another MySQL instance.
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the same exception & resolved the issue after 3 hectic days.Check if you are using I hibernate3. In this version it is req to explicitly mention the connection class name. Also check if the jar is in classpath. Check steps & comments in below link


autoReconnec=true doesnt seems to work..remove from config file.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!