Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Application Frameworks

Stripes, Spring, Wicket, etc

Cannot insert record into Database!


Hi guys,Below is the hibernate program I am trying to execute:contact.hbm.xml:code:<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping><class name="roseindia.tutorial.hibernate.Contact" table="CONTACT"><id name="id" type="int" column="ID"><generator class="assigned"/></id><property name="firstname"><column name="FIRSTNAME"/></property><property name="lastname"><column name="LASTNAME"/></property><property name="email"><column name="EMAIL"/></property></class></hibernate-mapping>hibernate.cfg.xml:code:<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD//EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property><property name="hibernate.connection.url">jdbc:mysql://localhost/hibernatetutorial</property><property name="hibernate.connection.username">root</property><property name="hibernate.connection.password">root</property><property name="hibernate.connection.pool_size">10</property><property name="show_sql">true</property><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="hibernate.hbm2ddl.auto">update</property><!-- Mapping files --><mapping resource="contact.hbm.xml"/></session-factory></hibernate-configuration>FirstExample.java:code:package roseindia.tutorial.hibernate;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;public class FirstExample {public static void main(String[] args) {try{// This step will read hibernate.cfg.xml and prepare hibernate for useSessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();Session session =sessionFactory.openSession();Transaction tx = session.beginTransaction();//Create new instance of Contact and set values in it by reading them from form objectSystem.out.println("Inserting Record .......");Contact contact = new Contact();contact.setId(2);contact.setFirstname("mike");contact.setLastname("dave");contact.setEmail("mike@hibernate.com");session.save(contact);tx.commit();session.flush();session.close();System.out.println("Done");}catch(Exception e){System.out.println(e);}}}[ June 17, 2007: Message edited by: v ray ]

   
   

   
   
      I'm getting the error:org.hibernate.exception.JDBCConnectionException: Cannot open connectionWhere have I gone wrong?? I'm checking the configuration file, it looks fine.Next, I look atSessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();which looks fine too.Is there something wrong with this line??Transaction tx = session.beginTransaction();Cant figure it out!!!

   
   

   
   
      Can you post the entire exception stacktrace.quote:<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:code:<property name="hibernate.connection.username">root</property><property name="hibernate.connection.password"></property>[ June 17, 2007: Message edited by: Jaikiran Pai ]--------------------My Blog

   
   

   
   
      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 connectionat 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.IOExceptionMESSAGE: Unexpected end of input streamSTACKTRACE:java.io.IOException: Unexpected end of input streamat 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

   
   

   
   
      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.--------------------My Blog

   
   

   
   
      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!

   
   
   
   
   
      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.--------------------http://ehemminger.orghttp://reverttoconsole.com


Related Links

Learning Spring Application Framework.
Browser Back button handling wusing spring
Stripes interceptor - what are you using them for?
Can quartz cron expression express the Fortnightly, Quarterly and Half yearly?
How to send an email using spring framework
Tapestry 5- Web Application framework:Question to Author
Simplifying a Spring AOP ProxyFactoryBean Definition
Uses of AOP in running web application
Spring versus Jee
download and run spring
Passing objects across controllers in Grails
Grails custom error messages
OnSuccess() not getting called in Tapestry 5.
Spring Requirements
Disposable bean's destroy method is not being called ???
Effect of using several frame work in a single web application