how to exeute mysql dump file in linux

create database Server_Sample_Dump character set utf8 collate utf8_bin;

use distribution_db;

source /home/ftuser/dump-local_Database_inv-201712041536.sql;

Advertisements

how many type we can create object in java

There are four different ways to create objects in java:

A. Using new keyword
This is the most common way to create an object in java. Almost 99% of objects are created in this way.

 MyObject object = new MyObject();

B. Using Class.forName()
If we know the name of the class & if it has a public default constructor we can create an object in this way.

MyObject object = (MyObject) Class.forName("subin.rnd.MyObject").newInstance();

C. Using clone()
The clone() can be used to create a copy of an existing object.

MyObject anotherObject = new MyObject();
MyObject object = (MyObject) anotherObject.clone();

D. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.

ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();

 

Example :

1.Test.Java

package com.example;
import java.io.Serializable;
public class Test implements Cloneable, Serializable {
private static final long serialVersionUID = 1L;
int a;

int b;
public int getA() {

return a;

}
public void setA(int a) {

this.a = a;

}
public int getB() {

return b;

}
public void setB(int b) {

this.b = b;

}
@Override public String toString() {

return “Test Object : ” + Integer.toString(a) + “,” + Integer.toString(b);

}
@Override protected Object clone() throws CloneNotSupportedException {

return super.clone();

}
}

2.Test2.Java

package com.example;
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;
public class Test2 {

public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, CloneNotSupportedException, IOException {
// Way 1 : Create object using new keyword

Test newKeywordObj = new Test();

newKeywordObj.setA(1);

newKeywordObj.setB(2);

System.out.println(“create object using new keyword :” + newKeywordObj);
// Way 2 : Create object using Class.forName

Test classFornameObj = (Test) Class.forName(“com.example.Test”).newInstance(); classFornameObj.setA(3);

classFornameObj.setB(4);

System.out.println(“create object using Class.forName :” + classFornameObj);
// Way 3 : Create object using clone method

Test cloneObj = (Test) newKeywordObj.clone();

System.out.println(“create object using clone method :” + cloneObj);
// Writing object into a file

Test writeObj = new Test();

writeObj.setA(10);

writeObj.setB(20);

FileOutputStream fout = null;

ObjectOutputStream oos = null;

fout = new FileOutputStream(“/home/ftuser/Documents/achyu/test.txt”);

oos = new ObjectOutputStream(fout);

oos.writeObject(writeObj);
// Way 4 : Creating a object from file using Object deserialization

FileInputStream anInputStream = new FileInputStream(“/home/ftuser/Documents/achyu/test.txt”);

ObjectInputStream inStream = new ObjectInputStream(anInputStream);

Test object = (Test) inStream.readObject();

System.out.println(“create object from file :” + object);
}}

 

Cannot add foreign key constraint – MySQL ERROR 1215 (HY000)

in the ddl query problem will occur

problem :

) ENGINE=InnoDB DEFAULT CHARSET=latin1

Solution :

) ENGINE=InnoDB DEFAULT CHARSET=utf8

 

Note : MySql storage engine should be ‘InnoDB’ and CHARSET should be ‘utf8’

 

More Reference :

Error Code: 1215. Cannot add foreign key constraint

Example:

Error Code: 1215. Cannot add foreign key constraint

 Possible Reason:

Case 1: MySQL storage engine.

MySQL supports several storage engines, comparing features of the different mysql storage engines are given below. Note that only InnoDB storage engine supports foreign key, when you are using different mysql storage engine you may get the error code: 1215 cannot add foreign key constraint.

MySQL STORAGE ENGINE FEATURES

Case 2: Key does not exist in the parent table.

When you are trying to reference a key on the parent table which is not exist, you may likely get the error code: 1215 cannot add foreign key constraint. When you are trying to reference a key on parent table which is not a candidate key (either a primary key or a unique key) you may get the error code: 1215 cannot add foreign key constraint. According to definition a foreign key must reference a candidate key of some table. It does not necessarily to be a primary key. MySQL requires index on corresponding referenced key, so you need a unique key.

Case 3: Foreign key definition.

When the definition of the foreign key is different from the reference key, you may get the error code: 1215 cannot add foreign key constraint. The size and sign of the integer must be the same. The character string columns, the character set and collation must be the same. Otherwise you may get the error code: 1215 cannot add foreign key constraint. The length of the string types need not be the same.

Case 4: Foreign key as a primary key.

When you are using composite primary key or implementing one-to-one relationships you may using foreign key as a primary key in your child table. In that case, definition of foreign key should not define as ON DELETE SET NULLSince primary key cannot be NULL, defining the referential action in such a way may produce the error code: 1215 cannot add foreign key constraint.

Case 5: Referential action – SET NULL.

When you specify SET NULL action and you defined the columns in the child table as NOT NULL, you may get the error code: 1215 cannot add foreign key constraint.

Solution:

Case 1: Storage Engine.

Only MySQL storage engine InnoDB supports foreign key, make sure you are using InnoDB storage engine. You can use the following command to determine which storage engine your server supports.

mysql > SHOW ENGINES \G

To determine the storage engine used in the corresponding table, you can run the following command:

mysql > SHOW CREATE TABLE table_name;

MySQL allows you to define storage engine on table level, you can assign the storage engine by using the following statement:

mysql > CREATE TABLE table_name (id INT) ENGINE = INNODB;

Example:

CREATE TABLE student (id INT NOT NULL, PRIMARY KEY (id)ENGINE=INNODB;

To alter the storage engine of an existing table, you can run the following statement:

mysql > ALTER TABLE table_name ENGINE = INNODB;

Case 2: Key does not exist in the parent table.

Make sure your parent table contains at least one key to which you are going to create a reference key.

You can use the following statement to check the definition of a table:


mysql > SHOW CREATE TABLE table_name;



If the key does not present in the table, you can create a new key by using following statement:

If your table does not have unique column, create a new unique data field and set it as unique so that you can have your existing data by using the following statement:


mysql > ALTER TABLE table_name ADD Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;



If the existing table contains the unique data field you can assign it as unique key, by using following statement:


mysql > ALTER TABLE table_name ADD CONSTRAINT constr_ID UNIQUE (column_name);

 

Case 3: Foreign key definition.

The data type must be same for both the foreign key and referenced key. The size and sign of integer types must be the same. For character strings the character set and collation must be the same.

Consider the following example to understand this case:

CREATE TABLE student(           
id TINYINT NOT NULL,                /* note the data type*/                  
PRIMARY KEY (id)
) ENGINE=INNODB; 

CREATE TABLE book
(                  
Id INT,
student_id INT,         /* data type different from the referencing data field*/                  
INDEX stu_ind (student_id),                  
FOREIGN KEY (student_id)
REFERENCES student(id)                  
ON DELETE CASCADE
) ENGINE=INNODB;

Note that, in the above example, the data type of the id in student table is TINYINT but the data type of the student_id column in book table which referencing the student table.

Here you need to alter the data type of the student_id column in book table. You can alter the data type of the existing column using following statement:

mysql > ALTER TABLE book MODIFY COLUMN  Id TINY INT NOT NULL ;

 After altering the required fields, the new statement may look as follows:

CREATE TABLE student (                   id TINYINT NOT NULL,                /* note the data type*/                  
PRIMARY KEY (id)
) ENGINE=INNODB; 

CREATE TABLE book
(                  
id INT,
student_id TINYINT NOT NULL,                   /* data type same as the referencing data field*/      INDEX stu_ind (student_id),                  
FOREIGN KEY (student_id)
REFERENCES student(id)                  
ON DELETE CASCADE
ENGINE=INNODB;

 

Case 4: Foreign key as a primary key.

When you are implementing one-to-one relationship or composite primary key you may use foreign key as a primary key in your child table. Definition of foreign key should not define as ON DELETE SET NULL. Since primary key cannot be NULL. The following example will illustrate this case better:

CREATE TABLE user (                  user_id INT NOT NULL,PRIMARY KEY (user_id)) ENGINE=INNODB;

CREATE TABLE student
(                  
user_id INT NOT NULL,             
PRIMARY KEY (user_id),           
FOREIGN KEY (user_id),                  
REFERENCES user (user_id),                  
ON DELETE CASCADE        /* Referential Action – ON DELETE not SET NULL */
) ENGINE=INNODB;

 

Case 5: Referential action – SET NULL.

Make sure when you specify SET NULL action, define the columns in the child table as NOT NULL.

The following example will explain this case clearly:

CREATE TABLE student (                   
id INT NOT NULL,
Reg_no varchar (255),                  
Key (Reg_no),          
PRIMARY KEY (id)
) ENGINE=INNODB; 

CREATE TABLE book
(                  
book_id INT,
reg_no varchar(255) NOT NULL,                 /* defined as NOT NULL*/                  
FOREIGN KEY (reg_no)
REFERENCES student(reg_no)                  
ON DELETE SET NULL                                        /*Action specified as SET NULL*/
) ENGINE=INNODB;

You can solve this by altering the foreign key column from not null to null. You can do that by using following statement: mysql > ALTER TABLE book MODIFY reg_no varchar(255) ;After modifying the table, the new statement may look similar to as follows:

CREATE TABLE student(

                  id INT NOT NULL,

                  Reg_no varchar (255),

                  Key (Reg_no),            

                  PRIMARY KEY (id)

)ENGINE=INNODB;

CREATE TABLE book

(

                  book_id INT, 

                  reg_no varchar(255) NULL,       /* allowed NULL*/

                  FOREIGN KEY (reg_no) 

                  REFERENCES student(reg_no)

                  ON DELETE SET NULL              /*Action specified as SET NULL*/

) ENGINE=INNODB;

 

 

When to use Inheritance and Aggregation?

Aggregation in Java

If a class have an entity reference, it is known as Aggregation. Aggregation represents HAS-A relationship.

Consider a situation, Employee object contains many informations such as id, name, emailId etc. It contains one more object named address, which contains its own informations such as city, state, country, zipcode etc. as given below.

  1. class Employee{
  2. int id;
  3. String name;
  4. Address address;//Address is a class
  5. }

In such case, Employee has an entity reference address, so relationship is Employee HAS-A address.

When to use Inheritance and Aggregation?

When you need to use property and behaviour of a class without modifying it inside your class. In such case Aggregation is a better option. Whereas when you need to use and modify property and behaviour of a class inside your class, its best to use Inheritance.

object comparision using id in angularjs drop down

In your example your objects don’t have the same properties so they are not going to be equal when using angular.equals. Your selectedGenres object has a ‘$$hashKey’ property on it (angular adds this) because you’re not a specifying tracking property. The objects in your $scope.genres array don’t have the ‘$$hashKey’ property. That’s why angular.equals is returning false.

If you add a track by property in your ng-options expression it will fix the issue.

ng-options="option as option.name for option in genres track by option.id"

could not create parent directory for lock file gradle ecplise

Step 1 : Remove All Gradle Folder from your computer
Step 2 : if gradle configuration is exisiting in profile
then remove those lines
ftuser@FT-LAPTOP-041:~$ cd /
ftuser@FT-LAPTOP-041:/$ cd etc
ftuser@FT-LAPTOP-041:/etc$ vi profile

Note : if not root user then use this command – sudo editor profile

Step 3: Download Gradle

sudo apt-get update

Gradle distribution archive comes in two types: “binary-only” and “complete”. The “binary-only” archive contains the Gradle software only wheres “complete” archive comes with binary, documentation and source. Run the following command to download Gradle to your system.

wget https://services.gradle.org/distributions/gradle-3.4.1-bin.zip
You can always check the Gradle release page to look for the link to the latest version of Gradle.

Step 4: Install Gradle

Create a directory for the Gradle installation.

sudo mkdir /opt/gradle
Extract the downloaded archive to the newly created directory.

sudo unzip -d /opt/gradle gradle-3.4.1-bin.zip
Configure the PATH environment variable so that the gradle executable can be directly executed anywhere on the system.

export PATH=$PATH:/opt/gradle/gradle-3.4.1/bin
You can run the following command to check if the Gradle install was successful.

gradle -v
You should see the following output.

————————————————————
Gradle 3.4.1
————————————————————

Build time: 2017-03-03 19:45:41 UTC
Revision: 9eb76efdd3d034dc506c719dac2955efb5ff9a93

Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_121 (Oracle Corporation 25.121-b13)
OS: Linux 4.8.0-41-generic amd64
The installation is complete. Your system is now ready to build programs using Gradle.