Setting up foreign keys in phpMyAdmin

Step 1:
You have to add the line:
default-storage-engine = InnoDB
under the [mysqld] section of your mysql config file (my.cnf or my.ini depending on your OS) and restart the mysqld service.

 

 

 

 

 

 

 

 

 

Step 2:
Now when you create the table you will see the type of table is: InnoDB

 

 

 

 

 

Step 3:
Create both Parent and Child table. Now open the Child table and select the coloum U like to have the Foreign Key:
Select the Index Key from Action Label as shown below.

 

 

 

 

 

Step 4:
Now open the Relation View in the same child table from bottom near the Print View as shown below.

 

 

 

 

 

Step 5:
Select the coloumn U like to have the Foreign key as Select the Parent coloumn from the drop down.
dbName.TableName.ColoumnName

Select appropriate Values for ON DELETE and ON UPDATE

 

Advertisements

Leave a comment

Filed under General

Java 8 : Lambda in Functional Interfaces

Lambda expressions in Java is usual written using syntax (argument) -> (body).

Functional Interface is an interface with just one abstract method declared in it.

Example:

ActionListener Interface
Runnable Interface
We generally use Anonymous inner classes to instantiate objects of functional interface but with the help of Lambda expressions, this can be simplified.

1

 

 

 

 

 

 

 

Output:

2

Leave a comment

Filed under Java

Java Packages – Tutorial 4

1. Expalin Package and what is need of package.

2. Creating Package.

/*

Code:

*/

package com.vinod;

public class Student {

private int id;
private String name;

public Student()
{
id=0;
name=null;
}
public Student(int tid,String tname)
{
id=tid;
name=tname;
}

public void setData()
{
id=0;
name=null;
}

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
System.out.println(“\n ID is:”+id);
System.out.println(“\n Name is:”+name);
}
}

package com.second;

public class Employee {

private int id;
private String name;

public void setData(int tid, String tname) {
id = tid;
name = tname;
}

public void display() {
System.out.println(“\nEmployee ID is:” + id);
System.out.println(“\nEmpoyee Name is:” + name);
}
}

package com.vinod;

import com.second.*;

public class MainClass {

public static void main(String[] args) {

Student stu1=new Student();
stu1.setData(1,”Vinod Pillai”);
stu1.display();

Student stu2=new Student(2,”Abc User”); //Calling Constructor with argument.
stu2.display();

Employee emp1=new Employee();
emp1.setData(101, “Ramesh”);
emp1.display();

com.second.Employee emp2=new com.second.Employee();
emp2.setData(102, “Xyz”);
emp2.display();
}
}

http://www.youtube.com/vinodthebest

1 Comment

Filed under General

Java Constructor, Method and Static variable – Tutorial 3

1. Method Overloading.

2. Constructors.

3. Constructors Overloading.

4. Static variable and Methods.

/*

Code:

*/

public class Student {

private int id;
private String name;

private static int count;

//Constructor Overloading
public Student()
{
//id=0;
name=null;

count++;
}
public Student(int tid,String tname)
{
id=tid;
name=tname;

count++;
}

//Method Overloading
public void setData()
{
id=0;
name=null;
}

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
System.out.println(“\n ID is:”+id);
System.out.println(“\n Name is:”+name);
}

//Static Method.
public static int getCount()
{
//System.out.println(“\n ID is:”+id); //Error can’t access not static Variable/Method
return count;
}
}

public class MainClass {

public static void main(String[] args) {

Student stu1=new Student();        //Calling the user defined default constructor.
stu1.setData(1,”Vinod Pillai”);

Student stu2=new Student(2,”Abc User”); //Calling Constructor with argument.
stu2.display();

int rel=Student.getCount(); //Accessing the Static method.
System.out.println(“\nThe Static result is:”+rel);
rel=0;

rel=stu2.getCount();    //Its not the correct way but this is allowed.
System.out.println(“\nThe New Static result is:”+rel);

Student stu3=new Student();
stu3.display();
}
}

 

 

http://www.youtube.com/vinodthebest

3 Comments

Filed under General

Java Classes and Objects – Tutorial 2

1. Creating Objects.

2. Creating Class in the same File.

3. Default value of the Class instance variable and Local variable.

Code:

/*

Student Class

*/

public class Student {

private int id;
private String name;

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
int testing=0;

System.out.println(“\n ID is:”+id);
System.out.println(“\n Name is:”+name);

System.out.println(testing);     //Not allowed without initialization
}
}

/*

Employee Class

*/
class Employee {

private int id;
private String name;

public void setData(int tid,String tname)
{
id=tid;
name=tname;
}

public void display()
{
System.out.println(“\nEmployee ID is:”+id);
System.out.println(“\nEmpoyee Name is:”+name);
}
}

/*

MainClass Class

*/
public class MainClass {

public static void main(String args[])
{
//Student Class
Student stuobj1=new Student(); //[ID/Name]

stuobj1.setData(1, “Vinod Pillai”);
stuobj1.display();

Student stuobj2;    //Reference created.

stuobj2=new Student(); //Memory is allocated now. [ID/Name]
stuobj2.display();        //Default values.
stuobj2.setData(2, “Vinod”);
stuobj2.display();

//Employee Class
Employee eobj=new Employee();
eobj.setData(1, “AbcXyz”);
eobj.display();
}
}

http://www.youtube.com/vinodthebest

Leave a comment

Filed under Java

Java Hello World – Tutorial 1

1. Java is an Object Oriented Programming language.

2. Importance of Class.

3. Creating simple “Hello World Application”.

4. Running the program.

5. Java works in two stage “Compiler and Interpreter” in Java.

Code:

public class MainClass
{
public static void main(String args[])
{
System.out.println(“\n Hello World \n”);
}
}
Prof. Vinod Pillai.
vinodthebest@gmail.com

http://www.youtube.com/vinodthebest

Leave a comment

Filed under Java

C++: Exception Handling Part 3

1. Explain Exception Handling.

2. Explain about specifying rethrowing exception.

3. Example showing the use of specifying rethrowing exception in C++.


/*
Developed By: Prof. Vinod Pillai
vinodthebest@gmail.com
Exception Handling-Part 3.
*/

#include

using namespace std;

void testException1() throw(int,char)
{
int val;

cout<>val;

if(val<=0)
{
throw(100);

//throw(‘a’);

//throw(10.56);
}
}

void testException2() throw()
{
int val;

cout<>val;

if(val<=0)
{
throw(100);
}
}

int main()
{
try
{
testException1();

//testException2();
}
catch(int value)
{
cout<<“\n——-Rethrow Integer Exception occured——-“;
}
catch(char value)
{
cout<<“\n——-Rethrow Character Exception occured——-“;
}
catch(…)
{
cout<<“\n——-Rethrow All Exception occured——-“;
}
return 0;
}

1 Comment

Filed under C++, Exception Handling