March 28, 2016

Convert java.util.Date > java.sql.Date > java.sql.Timestamp > java.text.SimpleDateFormat

java.util.Date : The class Date represents a specific instant in time, with millisecond precision.

Code :
 java.util.Date dtUtil = new java.util.Date();  
 System.out.println(dtUtil);  
Output :
Mon Mar 28 21:35:05 IST 2016

java.sql.Date : A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

long java.util.Date.getTime() :
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by Date object.

Code : Convert java.util.Date to java.sql.Date
 java.sql.Date dtSql = new java.sql.Date(dtUtil.getTime());  
 System.out.println(dtSql);  
Output :
2016-03-28

java.sql.Timestamp : A thin wrapper around java.util.Date that allows the JDBC API to identify this as an SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds.

Code :
 java.sql.Timestamp dtTime = new java.sql.Timestamp(dtUtil.getTime());  
 System.out.println(dtTime);  
Output :
2016-03-28 21:35:05.181

java.text.SimpleDateFormat : SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date ? text), parsing (text ? date), and normalization.

Code :
 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");  
 String dt = sdf.format(dtTime);
 System.out.println(dt);
Output :
28-03-2016 21:35:05

March 20, 2016

Jquery : Show label value on alert and browser console

Here, we are working with label, button and pop up message box where we are showing label value in message box on same page on submit button click using jquery.

index.jsp
console.log displays value(s) on browser console (Press F12 on browser then click on console tab to see console.log output) and alert on message box.

Jquery Download Link : http://jquery.com/download/
 
Output:

Also Read : How to show textbox value on message box with Jquery on button click

March 13, 2016

Charge your smartphone while your laptop lid is closed/off

Many-times I have to charge my mobile with my laptop but i can not down my laptop's lid because of phone charging goes off. But Now i can charge my mobile even by closing my laptop lid with a small change in Device Manager Setting.

Important : This will only work  when your laptop is charging (Not using Laptop Battery)

Device Manager >> Universal Serial Bus Controllers >> Generic USB Hub >> Properties


Power Management :
Uncheck "Allow this computer to turn off this device to save power"

If This solution is not working then go to your Laptop BIOS to Enable "USB Wake Support".

BIOS >> Advanced >> USB Wake Support

 Enable USB Wake Support and then exit with save. 

Also Read : Windows 8 : Add or Remove Sleep or Hibernate in Power Options Menu of your PC
Also Read : Stop or disable skype Auto-launching in Windows 8 on startup

SQL : Find 2nd or 3rd highest salary from employee table without ROWNUM or TOP

Employee Table
SELECT SALARY FROM EMPLOYEE ORDER BY SALARY DESC;

OUTPUT :  
SALARY
----------
     77777
     60000
     34000
     23232


Example to find the 2rd highest salary 

SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE);
 

OUTPUT :
MAX(SALARY)
-----------
      60000


Example to find the 3rd highest salary
After union query is omitting first highest salary.
SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM EMPLOYEE) UNION SELECT MAX(SALARY) FROM EMPLOYEE);
 

OUTPUT :
MAX(SALARY)
-----------
      34000


Also Read : Oracle and MySql : Find Top 3rd highest salary row from employee table

Disclaimer

We shall not be liable for the improper or incomplete transmission of the information contained in this communication nor for any delay in its response or damage to your system. We do not guarantee that the integrity or security of this communication has been maintained or that this communication is free of viruses, interceptions or interferences. Anyone communicating with us by email accepts the risks involved and their consequences. We accept no liability for any damage caused by any virus transmitted by this site.