aspose file tools*
The moose likes Other Application Frameworks and the fly likes Cannot insert record into Database! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Cannot insert record into Database!" Watch "Cannot insert record into Database!" New topic
Author

Cannot insert record into Database!

v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
Hi guys,
Below is the hibernate program I am trying to execute:

contact.hbm.xml:


hibernate.cfg.xml:


FirstExample.java:


[ June 17, 2007: Message edited by: v ray ]
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
I'm getting the error:

org.hibernate.exception.JDBCConnectionException: Cannot open connection

Where have I gone wrong?? I'm checking the configuration file, it looks fine.
Next, I look at
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

which looks fine too.
Is there something wrong with this line??

Transaction tx = session.beginTransaction();

Cant figure it out!!!
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Can you post the entire exception stacktrace.

<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>


Also if i remember correctly, by default, the 'root' user in MySQL does not have a password. You could try using the following:


[ June 17, 2007: Message edited by: Jaikiran Pai ]

[My Blog] [JavaRanch Journal]
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
No I've set the password as "root" as well.
As for the StackTrace:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record .......
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2048)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:28)
Caused by: java.sql.SQLException: Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream

** BEGIN NESTED EXCEPTION **

java.io.IOException
MESSAGE: Unexpected end of input stream

STACKTRACE:

java.io.IOException: Unexpected end of input stream
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:339)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:782)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1585)
at com.mysql.jdbc.Connection.<init>(Connection.java:524)
at com.mysql.jdbc.Driver.connect(Driver.java:359)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2048)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:28)


** END NESTED EXCEPTION **


at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:876)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1585)
at com.mysql.jdbc.Connection.<init>(Connection.java:524)
at com.mysql.jdbc.Driver.connect(Driver.java:359)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)
... 14 more
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Which version of MySQL JDBC driver jar do you have in your application classpath? Try using the latest version. A google search on this error led me to some posts which mentioned that this was because of using older version of MySQL jar.
v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
I have the 3.1 version, I think this is the latest one? Did someone try to execute this program on their system, maybe that will shed some light on what the mistake is?
The only part of the code I havent posted is the "Contact" class which has getter and setter methods for firstname,lastname, id and email.. Please help!
Jeff Hemminger
Greenhorn

Joined: Jun 15, 2007
Posts: 7
I assume you can access your mysql with the same credentials from another jdbc client? I like to use SquirrelSQL, because I can configure it to use the same drivers as my application.

Anyway, just want to verify that the issue isn't a connection issue rather than a spring issue.


<a href="http://ehemminger.org" target="_blank" rel="nofollow">http://ehemminger.org</a><br /><a href="http://reverttoconsole.com" target="_blank" rel="nofollow">http://reverttoconsole.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot insert record into Database!