Integration of hebernate and mysql

Source: Internet
Author: User

1. Download mysql,

How to install

2. start integrating hebernate in myeclipse

Some packages required by hebernate:

Configuration File: (Mysql has enabled remote connection)

 
 
 
  
   
    root
   
   
    jdbc:mysql://192.168.1.135:3306/SolarWorkFlowDb?useUnicode=true&characterEncoding=utf8
   
   
    org.hibernate.dialect.MySQLDialect
   
   
    mysqll
   
   
    solar
   
   
    com.mysql.jdbc.Driver
   
   
    true
   
   
    true
   
   
    true
   
   
    org.hibernate.cache.EhCacheProvider
       
   
  
 

Configuration File 2

 
 
     
          
   
    
Test Data
           
               
                
            
                    
               
            
                      
               
            
               
  
 

Entity class:

package test;public class Person {private int ID ;private String FULL_NAME;private String LAST_NAME;public Person(){}public Person(int iD, String fULLNAME, String lASTNAME) {super();ID = iD;FULL_NAME = fULLNAME;LAST_NAME = lASTNAME;}public int getID() {return ID;}public void setID(int iD) {ID = iD;}public String getFULL_NAME() {return FULL_NAME;}public void setFULL_NAME(String fULLNAME) {FULL_NAME = fULLNAME;}public String getLAST_NAME() {return LAST_NAME;}public void setLAST_NAME(String lASTNAME) {LAST_NAME = lASTNAME;}    }
Test class

package test;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.cfg.Configuration;public class TestPro {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubPerson p = new Person();p.setFULL_NAME("Tom");p.setLAST_NAME("LEE");Configuration cfg = new Configuration();SessionFactory sf = cfg.configure().buildSessionFactory();Session session = sf.openSession();session.beginTransaction();session.save(p);session.getTransaction().commit();session.close();sf.close();}}

Table Structure:

Test results:

MATERIALS: Click to open the link


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.