Posts

Showing posts from March, 2015

Java Hibernate - Part 3- Annotations Example

Image
Program to add Customer details in to MySQL Database using Hibernate 3.2 . Requirements:  Eclipse Keplor, MySQL 5.5,mysql-connector-odbc-5.2.5, Hibernate 3.2 (jars and xml files). Steps create a new java project named Sample1 add all hibernate jars to project build path. copy hibernate.cfg.xml to src folder Open MySQL command prompt  create Test database and use it. create Table named customer. create table customer(cid int primary key auto_increment,cname varchar(20),email varchar(20),phone varchar(15),city varchar(15),bal double); create a package named com.sam.hibernatefiles and write the following Customer.java(Hibernate Persistence class) HibernateUtil.java write the following client side code under package com.sam.hibernatefiles. Lab1A Customer.java package com.sam.hibernatefiles; import javax.persistence.*; @Entity @Table(name="customer") public class Customer { @Id @GeneratedValue(strategy=GenerationType.AUTO)

Java Hibernate- Part 2- Simple Example

Image
Program to add Customer details in to MySQL Database using Hibernate 3.1 . Requirements:  Eclipse Helios, MySQL 5.5,mysql-connector-odbc-5.2.5, Hibernate 3.1 (jars and xml files). Steps create a new java project named Sample1 add all hibernate jars to project build path. copy hibernate.cfg.xml to src folder Open MySQL command prompt  create Test database and use it. create Table named customer. create table customer(cid int primary key auto_increment,cname varchar(20),email varchar(20),phone varchar(15),city varchar(15),bal double); create a package named com.sam.hibernatefiles and write the following Customer.java(Hibernate Persistence class) Customer.hbm.xml (Hibernate mapping document to map your persistence class with table) HibernateUtil.java write the following client side code under package com.sam.hibernatefiles. Lab1A Customer.java package com.sam.hibernatefiles; public class Customer { private int cid; private String cname

C programming:-Files - Part 5

/*         Explain how do you create , open a file. WAP to read from a keyboard and write to a file and display its contents. Give examples.*/ #include<stdio.h> main() {             FILE *fp;             char s[30],s1[30];             printf("enter a string:");             gets(s); //read a string from terminal             fp=fopen("file1.txt","w");             fprintf(fp,"%s",s);//write string s to file1.txt             fclose(fp);             //display file contents             printf("file contents are: ");             fp=fopen("file1.txt","r");             fgets(s1,30,fp); //reads data from file to a string s1             printf("%s",s1);// display string s1 to the terminal } /*OUTPUT enter a string:hello students file contents are: hello students */ WRITE A C PROGRAM TO MERGE TWO FILES? #include<stdio.h> #include<conio.h> void main