Friday 10 February 2012

creating MySql database from XAMPP .

    Yesterday( 10-2-2012)  I learned  how to create a database using MySql which comes with XAMPP  software. 
     XAMPP software contains Apache WebServer, MySql5 database and PHP as well as Perl  scripting engines.
   I give below the steps required for creating 
database named 'mycontacts' in MySql.


go to  c:\xammp\mysql\bin


>mysql -u  root
Now you are taken to the mysql prompt


mysql>create  database  mycontacts;


>use mycontacts;


>create  table mycontactstable(id  varchar(4) primary key,name  varchar(20),phone  varchar(10));




 Initializing ID field can be of either auto incremented or assigned. In this database I am going to assign the ID. so, It can be of any of the data types. I have declared it as String (varchar)type.  If you choose auto Increment, the ID field should be declared of Integer type.        


>select *   from mycontactstable;


Initially You won't get any entry.


>insert  into  mycontactstable  values('101', 'tom','98762');




>insert  into  mycontactstable  values('102', 'sam','98476');


After making a few entries, test


>select *  from mycontactstable;


you will get your records in mycontactstable.


I am going to use this table for my experiment 
on Hibernate. In Hibernate mapping document, we
mention about generator type. It refers to the way  in which primary key is generated. Many 
databases have provision for auto-increment.
In that case, it will be a number.
If so,the following syntax is used to get a record in
Hibernate code.


   int   n = Integer.parseInt(c);
    etc.


If we are using String type for Id field, it is not necessary. I just wanted to make things as simple as possible.