Friday 22 June 2012

Unzip *.zip files in ubuntu

To extract *.zip files in ubuntu via command use the following command
     
                                "unzip  Path of *.zip file"

Example :

Your file location is /home/test/test.zip  then use command like below

unzip /home/test/test.zip

Now you get  unzipped test file

                       

Resolve Subquery returns more than one row in SQL

Subquery can be  used to return records that will be used in the main query as a condition to further restrict the records to be retrieved.
While you retriving data from database you can get error like  "Subquery returns more than one row ".That is subquery returns more than one row for your condtion.
In main query means that will not affect.In subquery will return only one row at that time.For that we can use "GROUP_CONCAT" for combining more than one row as a single row.now that error will gone away.

Example:

SELECT
     ID as id,
     (SELECT NAME  FROM DEPARTMENT where ID='1') as name,
FROM
     ASSOCIATION
WHERE
   NAME LIKE "%raja%"

in that ID=1 having more than one data means return more rows.For you can use like that
 GROUP_CONCAT(SELECT NAME  FROM DEPARTMENT where ID='1') as name means it will return one row with comma separated values..(ram,raj,raja) like that









Tuesday 12 June 2012

The use of instanceof Keyword in Java

The instanceof keyword in java which is used to test if an object is of a specified type.The general form of instanceof Keyword is

                                              "object instanceof type"

Here, the object is an instance of a class, and type is a class type. If object is of the specified type or can be cast into the specified type, then the instanceof Keyword evaluates to true. Otherwise, it evaluates false.It is the means by which your program can obtain run-time type information about an object.

Example:
public class test {
  public static void main(String[] b) {
    String temp = "Hello";
    if (temp instanceof java.lang.String) {
      System.out.println("yes it's true");
    }else {
      System.out.println("Oops it's false");
    }
  }
}

However, above example returns yes it's true.Because String temp is instanceof of java.lang.String.

if you declare String temp=null means it returns Oops it's false.Because applying instanceof on a null reference variable returns false

Another  Example is


class A {
  public A() {

  }
}
class B extends A {
  public B() {
    super();
  }
}
public class MainClass {
  public static void main(String[] test) {

    B b= new B();
    if (b instanceof A) {
      System.out.println("true");
    }
  }
}

it returns true.Because class B is instanceof of A.

Monday 11 June 2012

Fixing problem of MySQL server has gone away in Windows

While doing some operations like import files in MySQL error coming like "MySQL server has gone away".It is same PacketTooBigException in Linux.For that you have to execute the following Query in MySQL
                    "set global max_allowed_packet=16777216"
after executing this query do your operation.Error will not occur.