Sunday Feb 05
Move
Display 0 | 5 | 10 | 15 Stories

Gadget

Topics
Top Story

Waterproof LCD for Bathrooms

Waterproof LCD for Bathrooms

  Have you been wishing for a waterproof LCD TV for use in you bathroom? Good for you, Vu has launched...

PlayStation 4 Release date and Features

PlayStation 4 Release date and Features

  The next generation PlayStation may arrive sooner than we think.. maybe even in 2009! But based...

XBox 720 Release date and Features

  In an interview with the head of Microsoft’s Interactive Entertainment Business division, Peter...

Wii 2 Release date and Features

  Nintendo are selling Wii’s faster than stores can stock them and some may believe that they...

PSP 2 Release date and Features

  The PS2P should be available in 2009 - 10, to compete with the upgraded Nintendo DS. Some features...

Upcoming Game Consoles

Gadget

Move
Display 0 | 5 | 10 | 15 Stories

Software Tutorials

Topics
Top Story

How to Enable / Disable Autoformat in word 2007

How to Enable / Disable Autoformat in word 2007

  The interface of Office 2007 does does not offer an intuitive tool to enable or disable the autocorrect...

How to use old MSN Messenger without upgrading

  If you dont like the newer version of MSN Live Messenger and want to use the old MSN Messenger...

Software Tutorials

 

Move
Display 0 | 5 | 10 | 15 Stories

General

Topics
Top Story

PRAM model of Parallel Computation

PRAM model of Parallel Computation

  A PRAM consists of a control unit, global memory, and an unbounded set of processors,each with its...

The Crisis of Credit Visualized

A Vimeo video by Jonathan Jarvis attempting to visually explain the credit crisis -   The Crisis...

How to carry money while travelling

If you are planning to go abroad for any purpose, like higher studies, tourism or business purpose,...

How to call from US to india

  There are many ways to call back to india You can take a sim card from the Matrix company and...

Translation of source code to object module : The Preprocessor Compilation Process

The preposessor (We'll be talking of the C preprocessor) is a seperate program invoked by the compiler...

Virtua Kitchen - The Kitchen Operating System

What is a Synergistic Processing Element / SPE

What is a Power Processor Element / PPE

What is the Element Interconnect Bus / EIB

What is the Cell Architecture

Why use Automated Testing Tools

What is the Software Testing Life Cycle (STLC)

What is Software Testing

AudioSurf - Ride Your Music !

Ubuntu 8.10 is out!

Move
Display 0 | 5 | 10 | 15 Stories

Programming

Topics
Top Story

Code for Writing a xlsx file in java

Here is a small code to write xlsx file though java code.    You may need to include some of...

Code for Reading a xlsx file in java

Here is a small code to read xlsx file thoug java code.    You may need to include some of the...

How to read and write data from socket in java

   ServerSocket serverSocket=new ServerSocket(port);  // The below statement will wait for the...

Producer Consumer Problem in C using Semaphores and Shared Memory

  The classic bounded-buffer problem can be implemented using a variety of synchronization mechanisms....

Common Intermediate Language

Common Intermediate Language (formerly called Microsoft Intermediate Language or MSIL) is the lowest-level...

Common Type System in C#

Common Language Runtime

A Quick Introduction to C# Features

Code for updating database using hibernate framework in java

Conversion of int to byte and vice versa

Web Crawler in Python

Neural Network in Python

Programming

Move
Display 0 | 5 | 10 | 15 Stories

Graphics

Topics
Top Story
Move
Display 0 | 5 | 10 | 15 Stories

Linux

Topics
Top Story

Linux

 

Move
Display 0 | 5 | 10 | 15 Stories

Web

Topics
Top Story

What is Kosmix

  I am guessing that you looked up the term ' What is Kosmix ' on google after hearing somewhere about...

What is a meta tag

  There was a time when I didnt know of Meta tags myself. I'm glad I do now as they have really helped...

Why some search results have no description

  Before I go on to explain why some search results have no description , I woud like to state that...

What is the Facebook Bill of Rights

Have you also been wondering what the facebook bill of rights is? Here is the short answer to the popular...

The Fastest Safari Browser

  Apple has announced the public beta of Safari 4 for Macintosh and Windows PCs, which is the fastest...

Web

Move
Display 0 | 5 | 10 | 15 Stories

Games

Topics
Top Story

Games

 

Move
Display 0 | 5 | 10 | 15 Stories

Windows

Topics
Top Story

Windows

 

Code for updating database using hibernate framework in java

(0 votes, average: 0 out of 5)





Here is a simple hibernate program to update the table in the mysql. You can makeyour first code as given below and set the xml file accordingly. I have made the code run in the netbeans so the formatting is done accordingly.
This program will try to connect to the mysql database with the username and password given the xml file.

Include the following
·    Hibernate framework
·    Commons-lang-2.4.jar
·    Mysql-connector-java-5.1.5-bin.jar

Make a package hibernate1

Save this file as Main.java

package hibernate1;

import org.hibernate.*;

import org.hibernate.cfg.*;


public class Main {

    

    public static void main(String[] args) {
        // TODO code application logic here

        Session session = null;

    try{
      // This step will read hibernate.cfg.xml

        //Session sess=HibernateUtil.currentSession();

              SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
       session =sessionFactory.openSession();
        //Create new instance of Contact and set


         System.out.println("Inserting Record");
        Contact contact = new Contact();
        long a=1;
        contact.setId("5");
        contact.setFirstName("Deepak1");
        contact.setLastName("Kumar");
        //contact.setEmail("deepak");
        System.out.println(contact.getFirstName());
        Transaction tr = session.beginTransaction();
      //Contact ins = (Contact)session.get(Contact.class, "1");
      //ins.setFirstName("Jivan Dhara");
      
      //ins.setInvestementDate(new Date());
      //session.update(ins);
      session.save(contact);
      
      tr.commit();
      session.close();
        //session.save(contact);
        System.out.println("Done");
        //session.flush();
      //session.close();
    }catch(Exception e){
      //System.out.println(e.getMessage());
      e.printStackTrace();
    }finally{
      // Actual contact insertion will happen at this step
      

      }

  }
    }

Now make a xml file outside the package directory and save it as  hibernate.cfg.xml

"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">



      org.gjt.mm.mysql.Driver
      jdbc:mysql://localhost:3306/test
      root
      admin
      10
      true
      org.hibernate.dialect.MySQLDialect
      update
     
     



Now make a Contact.java


package hibernate1;


public class Contact {

  private String firstName;
  private String lastName;
 
  private String id;

 
  public String getFirstName() {
    return firstName;
  }

 
  public String getLastName() {
    return lastName;
  }

 
  public void setFirstName(String string) {
    firstName = string;
  }

 
  public void setLastName(String string) {
    lastName = string;
  }

 
  public String getId() {
    return id;
  }

 
  public void setId(String l) {
    id = l;
  }
}
Now make a corresponding xml file for Contact and save in the same directory as Contact.java
Save the xml file as Contact.hbm.xml

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


 
  
  
 

 
    
 

 
   
 

 
 





Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Google! Live! Facebook! Slashdot! Technorati! StumbleUpon! Spurl! Furl! Yahoo! Squidoo! Ask! DZone! Free Joomla PHP extensions, software, information and tutorials.



Comments

B
i
u
Quote
Code
List
List item
URL
Name *
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment

Tag Cloud

Login Form