May 21, 2016

Bootstrap : Prevent or disable Modal pop up disappearing while outside click or pressing escape

Problem : I am working with Bootstrap Modal to display pop up window but whenever i click outside the modal or press escape button it goes disappear but i want to manually close it by clicking close button on modal pop up.

Solution : To disable on click set backdrop option as static and to prevent closing of the modal by esc button set keyboard option as false as shown in below given code.

1. If you are using javascript for displaying Modal.
$('#myModal').modal({backdrop: 'static', keyboard: false})  

2. If you are using data attributes on html or jsp.
<button data-backdrop="static" data-keyboard="false" data-target="#myModal" 
data-toggle="modal">  
Click Here for Modal  
</button>`  

May 3, 2016

Flush DNS cache - solved server not found Error

If you know that your internet is working fine and still you are facing this error on visiting website's URL. Then below given solution can solve your problem.
Problem :
Server not found
Firefox can't find the server at www.blogger.com.
  • Check the address for typing errors such as ww.example.com instead of www.example.com
  • If you are unable to load any pages, check your computer's network connection.
  • If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.
Solution :
Step 1: Open Command prompt : Press Window Key + R, type cmd then click on OK button.
Step 2 : Type ipconfig /flushdns and press Enter. A message will appear stating Windows IP configuration Successfully flushed the DNS Resolver Cache.
Step 3 : Type exit on command prompt to close command prompt.

April 23, 2016

Disable or enable input field using jQuery and JavaScript

JavaScript :
We can disable or enable an input box by setting property true or false respectively by using below code.
Code of input box
Name: <input type="text" id="myName">

To Disable input box.
document.getElementById("myName").disabled = true;

To Enable input box.
document.getElementById("myName").disabled = false;

jQuery :
If you are using jQuery 1.6+ then you should use the .prop() function to disable or enable input field.
$("input").prop('disabled', true);
$("input").prop('disabled', false);

Above code will disable all the input fields, if you want to disable or enable particular field, then you should use class or id of that particular input field.
Name: <input type="text" id="myName" class="myName"> 
$("#myName").prop('disabled', true);  // using id of input box
$(".myName").prop('disabled', false); // using class of input box

If you are using jQuery 1.5 or below then you should use the .attr() function.
To disable input field:
$("input").attr('disabled', 'disabled');

To enable input field:
$("input").removeAttr('disabled');

There is also .removeProp like .removeAttr in jQuery 1.6 but we should not use it because once you use removeProp you can not again disable it.

April 17, 2016

JavaEE : oracle.jdbc.OracleTypes for CallableStatement.registerOutParameter with SYS_REFCURSOR

This is a procedure which has one out parameter of SYS_REFCURSOR type.
PROCEDURE p_get_data(query_result OUT SYS_REFCURSOR);

In java for working out with this procedure you need to import ojdbc14.jar and need to set registerOutParameter type as OracleTypes.CURSOR
import oracle.jdbc.driver.OracleTypes;

CallableStatement callStmt = connection.prepareCall("{call p_get_data(?)}");
callStmt.registerOutParameter(1, OracleTypes.CURSOR);
callStmt.execute();
ResultSet resultSet = (ResultSet) callStmt.getObject(1);
if(resultSet.next()) {
//Your Code here
} 

April 2, 2016

Oracle SQL Developer : Display both date and time

SQL Developer date and time column returns only date so if you want to see both date and time on SQL developer then you have to make just a small change in SQL Developer's Preferences.

Go to Tools  >> Preferences
Preferences >> Database >> NLS 
set the Date Format as DD-MON-RR HH24:MI:SS

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.