How to Excel Export from MySQL

How to excel export a table from MySql.

Here is the command
TableName : EmpData.

Query:
Select * from EmpDate INTO OUTFILE 'empDate.xls';

The exported file will be save on the following path
"C:\ProgramData\MySQL\MySQL Server 5.5\data\<<DatabaseName-Folder>>"

MySql : How to Display the Month Names between a given range column wise

Displaying Month Names Column wise in a given range

SELECT MONTHNAME(STR_TO_DATE(6, '%m')) Month;
OUTPUT

+---------------------------------+
| Month                                   |
+---------------------------------+
| June                            |
+---------------------------------+


Now How to Display all months from JAN to DEC.

select STR_TO_DATE(CONCAT('01-',date_format(STR_TO_DATE(a1.months,'%m'),'%b'),'-11'),'%d-%b-%y') as date
from (select 1 months union select 2 union select 3 union select 4 union select 5 union select 6 union
select 7 months union select 8 union select 9 union select 10 union select 11 union select 12) a1


OUTPUT
+------------+
| date            |
+------------+
| 2011-01-01 |
| 2011-02-01 |
| 2011-03-01 |
| 2011-04-01 |
| 2011-05-01 |
| 2011-06-01 |
| 2011-07-01 |
| 2011-08-01 |
| 2011-09-01 |
| 2011-10-01 |
| 2011-11-01 |
| 2011-12-01 |
+------------+
Here I concatinated '2011' Year so we are getting all 2011 months. I am displaying first date of each month. Suppose if you want only Month and Year Names as Output.
select MONTHNAME(STR_TO_DATE(a1.months, '%m')) as date
from (select 1 months union select 2 union select 3 union select 4 union select 5 union select 6 union
select 7 months union select 8 union select 9 union select 10 union select 11 union select 12) a1

Output
+-----------+
| date      |
+-----------+
| January   |
| February  |
| March     |
| April     |
| May       |
| June      |
| July      |
| August    |
| September |
| October   |
| November  |
| December  |
+-----------+

Now the Original question How to get the dates between given date range for example Oct-2011 to May-2012.

select * from (
select STR_TO_DATE(CONCAT('01-',date_format(STR_TO_DATE(a1.months,'%m'),'%b'),'-11'),'%d-%b-%y') as date
from (select 1 months union select 2 union select 3 union select 4 union select 5 union select 6 union
select 7 months union select 8 union select 9 union select 10 union select 11 union select 12) a1 
UNION
select STR_TO_DATE(CONCAT('01-',date_format(STR_TO_DATE(a2.months,'%m'),'%b'),'-12'),'%d-%b-%y') as date
from (select 1 months union select 2 union select 3 union select 4 union select 5 union select 6 union
select 7 months union select 8 union select 9 union select 10 union select 11 union select 12) a2
) b where date between STR_TO_DATE('01-Oct-11','%d-%b-%y') and STR_TO_DATE('01-may-12','%d-%b-%y');


Output
+------------+
| date       |
+------------+
| 2011-10-01 |
| 2011-11-01 |
| 2011-12-01 |
| 2012-01-01 |
| 2012-02-01 |
| 2012-03-01 |
| 2012-04-01 |
| 2012-05-01 |
+------------+






How to Convert MM/DD/YYYY format to YYYY-MM-DD HH:MM:SS in Java

How to Convert MM/DD/YYYY format Date to DB Format which is YYYY-MM-DD HH:MM:SS  using Java


//Required Imports

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

//Define outputDate variable
Timestamp outputDate = null;
 //input datestring in MM/DD/YYYY format 
String inputDate = "05/16/2013";
try {    
//create a simpledateformat object to read the input date
 SimpleDateFormat fromDate = new SimpleDateFormat("MM/dd/yyyy");
//create one more simpledateformat object to write output date
 SimpleDateFormat toDBFormat = new SimpleDateFormat("yyyy-MM-dd");
//Parse Input Date to Output format as a String
 String reformattedStr = toDBFormat.format(fromDate.parse(inputDate));
//Now Convert the string to Date
 Date parsedDate = toDBFormat.parse(reformattedStr);
//Now finally convert the Date to Timestamp format which is equivalent to MySQL Format
 transactionDate = new java.sql.Timestamp(parsedDate.getTime());
}catch(Exception e) {
  e.printStackTrace();                       
}

MySql Custom Order By using FIELD

I have the following Table : US_States

Id  State
1   CA
2   TX
3   IL
4   MO
5   MI
6   OH
7   CO
8   AZ
9   NY
10 OR


Now I want to display all States in alphabetical order but TX, CA, IL at last. This problem can be solved using FIELD in mysql
FIELD(<FieldName>, Data1, Data2, Data3)

SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL) , State;

If you don't Give State at the end the above states are displayed in Random Order
SELECT * FROM US_States ORDER BY FIELD(State, TX,CA,IL);

Kaspersky Anti Virus 2013 can't be installed : Solved

A few days ago I puchased kaspersky Anti Virus 2013, I have tried to install it, but it cannot be installed after the entire setup is completed. I keep getting error at the end of the Installation which says "Kaspersky AntiVirus 2013 cannot be installed". I have tried all the trouble shooting steps to get that installed by following the below link

My system is running Windows XP Service Pack 3

http://support.kaspersky.com/8033

My computer is neither having any virus not any Antivirus Program. I tried Rescue disk and did all the scanning which took 3-4 hours of my time. All the scanning went in vain.

Next I tried Kaspersky virus Removal Tool, even this failed.

How I solved the Problem Finally :

I downloaded Kaspersky 2012 (older version) from http://www.filehippo.com/download_kaspersky_antivir/

Exact download link : http://www.filehippo.com/download_kaspersky_antivir/10377/

This installation went fine and I successfully installed the application and activated it with my 2013 key.

Hope this saves lot of time for any one out there.