Welcome to my blog, hope you enjoy reading
RSS

Monday 29 July 2013

Short form for Java If statement

Short form for Java If statement

problem:
if (city.getName() != null) {
    name = city.getName();
} else {
    name="N/A";
}

Solution:
name = ((city == null) || (city.getName() == null) ? "N/A" : city.getName());
Share

Friday 19 July 2013

How to call URL from JAVA

How to call URL from JAVA



package com.javanotes2all.java.reqRes;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class CallUrl 
{
  public static void main(String[] args) 
  {
         URL url;
         try 
         {
             // get URL content
             String a="http://docs.oracle.com/javase/tutorial/jdbc/basics/sqldatasources.html";
             url = new URL(a);
             URLConnection conn = url.openConnection();
             // open the stream and put it into BufferedReader
             BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
             String inputLine;
             while ((inputLine = br.readLine()) != null) {
                     System.out.println(inputLine);
             }
             br.close();

             System.out.println("Done");

         } catch (MalformedURLException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }

     }

}


Share

Wednesday 17 July 2013

case sensitive and insensitive condition in String replace function

case sensitive and insensitive condition in String replace function

            String target = "FooBar";
   target = target.replaceAll("foo", "");
   System.out.println(target); 
In java the above statements output is 'FooBar'
Share

Monday 15 July 2013

case sensitive and insensitive condition in mysql

case sensitive and insensitive condition in mysql

In database normally we write the condition then bydefault it is caseinsensitive.
//case insensitive condition in mysql

SELECT * FROM myTable WHERE 'something' = 'Something'

= 1

//case sensitive condition in mysql

This is a select with binary

SELECT * FROM myTable WHERE BINARY 'something' = 'Something'

or

SELECT * FROM myTable WHERE 'something' = BINARY 'Something'= 0
Share

Saturday 13 July 2013

MySQL: Update multiple tables with multiple columns

MySQL: Update multiple tables with multiple columns

Table1







Share

Monday 8 July 2013

Java beep sound example

Java beep sound example

There are different ways to generate a beep sound in java. The general basic way to generate is to use java.awt.Toolkit class which has a default method to generate the beep sound. The other implementation is also shown below on how to generate beep sound in java.
Share