Hi,
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 like this :
[java] java.sql.SQLException: Cannot connect to MySQL server on localhost:33
06. Is there a MySQL server running on the machine/port you are trying to connec
t 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"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- 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"/>
</session-factory>
</hibernate-configuration>
and this is my complete log message from ant :
E:\TES\development>ant run -Daction=store
Buildfile: build.xml
clean:
[delete] Deleting directory E:\TES\development\bin
[mkdir] Created dir: E:\TES\development\bin
copy-resources:
[copy] Copying 3 files to E:\TES\development\bin
[copy] Copied 2 empty directories to 1 empty directory under E:\TES\develop
ment\bin
compile:
[javac] Compiling 3 source files to E:\TES\development\bin
run:
[java] 15:43:18,281 INFO Environment:479 - Hibernate 3.1.3
[java] 15:43:18,312 INFO Environment:509 - hibernate.properties not found
[java] 15:43:18,312 INFO Environment:525 - using CGLIB reflection optimize
r
[java] 15:43:18,328 INFO Environment:555 - using JDK 1.4 java.sql.Timestam
p handling
[java] 15:43:18,515 INFO Configuration:1308 - configuring from resource: /
hibernate.cfg.xml
[java] 15:43:18,515 INFO Configuration:1285 - Configuration resource: /hib
ernate.cfg.xml
[java] 15:43:19,343 INFO Configuration:469 - Reading mappings from resourc
e: events/Event.hbm.xml
[java] 15:43:19,671 INFO HbmBinder:309 - Mapping class: events.Event -> EV
ENTS
[java] 15:43:19,765 INFO Configuration:1419 - Configured SessionFactory: n
ull
[java] 15:43:19,953 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 15:43:19,968 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 15:43:19,968 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 15:43:20,015 INFO DriverManagerConnectionProvider:80 - using driver
: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/hibernate
[java] 15:43:20,015 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {user=hibernate_user, password=****}
[java] 15:43:20,359 WARN SettingsFactory:103 - Could not obtain connection
metadata
[java] java.sql.SQLException: Cannot connect to MySQL server on localhost:33
06. Is there a MySQL server running on the machine/port you are trying to connec
t to? (java.lang.NumberFormatException)
[java] at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
[java] at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source
)
[java] at com.mysql.jdbc.Driver.connect(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at org.hibernate.connection.DriverManagerConnectionProvider.getC
onnection(DriverManagerConnectionProvider.java:110)
[java] at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFacto
ry.java:72)
[java] at org.hibernate.cfg.Configuration.buildSettings(Configuration.j
ava:1881)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1174)
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] 15:43:20,468 INFO Dialect:103 - Using dialect: org.hibernate.dialec
t.MySQLDialect
[java] 15:43:20,500 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 15:43:20,500 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 15:43:20,500 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 15:43:20,500 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 15:43:20,515 INFO SettingsFactory:144 - Scrollable result sets: dis
abled
[java] 15:43:20,515 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 15:43:20,515 INFO SettingsFactory:160 - Connection release mode: au
to
[java] 15:43:20,546 INFO SettingsFactory:184 - Maximum outer join fetch de
pth: 2
[java] 15:43:20,546 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 15:43:20,546 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 15:43:20,546 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 15:43:20,546 INFO SettingsFactory:338 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 15:43:20,578 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTran
slatorFactory
[java] 15:43:20,578 INFO SettingsFactory:203 - Query language substitution
s: {}
[java] 15:43:20,578 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 15:43:20,593 INFO SettingsFactory:213 - Query cache: disabled
[java] 15:43:20,593 INFO SettingsFactory:325 - Cache provider: org.hiberna
te.cache.NoCacheProvider
[java] 15:43:20,609 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 15:43:20,609 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 15:43:20,640 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 15:43:20,640 INFO SettingsFactory:264 - Statistics: disabled
[java] 15:43:20,640 INFO SettingsFactory:268 - Deleted entity synthetic id
entifier rollback: disabled
[java] 15:43:20,640 INFO SettingsFactory:283 - Default entity-mode: pojo
[java] 15:43:20,734 INFO SessionFactoryImpl:154 - building session factory
[java] 15:43:21,671 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 15:43:21,687 INFO SchemaExport:152 - Running hbm2ddl schema export
[java] 15:43:21,687 DEBUG SchemaExport:168 - import file not found: /import
.sql
[java] 15:43:21,687 INFO SchemaExport:177 - exporting generated schema to
database
[java] 15:43:21,734 ERROR SchemaExport:200 - schema export unsuccessful
[java] java.sql.SQLException: Cannot connect to MySQL server on localhost:33
06. Is there a MySQL server running on the machine/port you are trying to connec
t to? (java.lang.NumberFormatException)
[java] at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
[java] at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source
)
[java] at com.mysql.jdbc.Driver.connect(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at org.hibernate.connection.DriverManagerConnectionProvider.getC
onnection(DriverManagerConnectionProvider.java:110)
[java] at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnecti
onHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
[java] at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.
java:178)
[java] at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.j
ava:131)
[java] at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryIm
pl.java:295)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configura
tion.java:1176)
[java] at util.HibernateUtil.<clinit>(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] 15:43:22,250 WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState
: 08S01
[java] 15:43:22,265 ERROR JDBCExceptionReporter:72 - Cannot connect to MySQ
L server on localhost:3306. Is there a MySQL server running on the machine/port y
ou are trying to connect to? (java.lang.NumberFormatException)
[java] Exception in thread "main" org.hibernate.exception.JDBCConnectionExc
eption: Cannot open connection
[java] at org.hibernate.exception.SQLStateConverter.convert(SQLStateCon
verter.java:74)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:29)
[java] at org.hibernate.jdbc.ConnectionManager.openConnection(Connectio
nManager.java:420)
[java] at org.hibernate.jdbc.ConnectionManager.getConnection(Connection
Manager.java:144)
[java] at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:12
9)
[java] at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransacti
on.java:57)
[java] at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.j
ava:1290)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Sourc
e)
[java] at java.lang.reflect.Method.invoke(Unknown Source)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionPr
otectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.beginTransaction(Unknown Source)
[java] at events.EventManager.createAndStoreEvent(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Cannot connect to MySQL server on
localhost:3306. Is there a MySQL server running on the machine/port you are tryin
g to connect to? (java.lang.NumberFormatException)
[java] at com.mysql.jdbc.Connection.connectionInit(Unknown Source)
[java] at com.mysql.jdbc.jdbc2.Connection.connectionInit(Unknown Source
)
[java] at com.mysql.jdbc.Driver.connect(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at java.sql.DriverManager.getConnection(Unknown Source)
[java] at org.hibernate.connection.DriverManagerConnectionProvider.getC
onnection(DriverManagerConnectionProvider.java:110)
[java] at org.hibernate.jdbc.ConnectionManager.openConnection(Connectio
nManager.java:417)
[java] ... 12 more
[java] Java Result: 1
BUILD SUCCESSFUL
|