Friday, 22 April 2016

Convert Java (JDBC) ResultSet to JSON Using RStoJSON API in Java

This API  is develop by me.It convert ResultSet to JSON String..By invoking a static Method present in Converter CLASS.(download RStoJSON.jar from here)

ResultSet rs=ps.executeQuery();
 

String jsonString=com.learners.converter.Converter.rsTojson(rs);

Use Code As
Set jar file in lib Folder
It will give Out put As
(its a web service output on postman)

Thursday, 21 April 2016

How to make ResultSet Object to JSON String in Java

package com.learners.converter;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection;

/**
 * @author jyotioeuvretc.com
 *
 */
public class Converter {

 /**
  * @param args
  */
 public static void main(String[] args) {
     try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://192.168.0.29/scylla","root","root");
PreparedStatement ps=con.prepareStatement("SELECT * FROM view_promocode_doctor ");
ResultSet rs=ps.executeQuery();
ResultSetMetaData rsm=rs.getMetaData();
System.out.println("col="+rsm.getColumnCount()+"table="+rsm.getTableName(1));
ArrayList<StringBuilder> collist=new ArrayList<StringBuilder>();
  
while(rs.next()){
StringBuilder sb=new StringBuilder();
sb.append("{");
for(int i=1;i<rsm.getColumnCount()+1;i++){ 
   
    //System.out.println(rsm.getColumnName(i)+":"+rs.getString(i)+",");
if(i==rsm.getColumnCount())
{
 sb.append("\""+rsm.getColumnName(i)+"\":\""+rs.getString(i)+"\"");
}
else
{
 sb.append("\""+rsm.getColumnName(i)+"\":\""+rs.getString(i)+"\",");
}
}
    
sb.append("}");
collist.add(sb);
}
//OutPut
 System.out.println(collist.toString());
  
 } catch (Exception e) {
  e.printStackTrace();
 }
     
     
  
 }

}
          


It give Output As....

 

Tuesday, 19 April 2016

How to Use media Query in CSS to change the style according to screen width ?

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
    background-color:lightgreen;
}


@media only screen and (max-width:600px){
   body{
        background-color:black;

     }
}
@media only screen and (max-width: 500px) {
    body {
        background-color:lightblue;
    }
}
</style>
</head>
<body>
<p>Resize the browser window. When the width of this document is less than 500 pixels,
 the background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>

It will work as....







Resize the browser window. When the width of this document is
less than 500 pixels, the background-color is "lightblue",
otherwise it is "lightgreen".

how to filter input element in html 5 ?

Only audio.....<input accept="audio/*;capture=microphone" type="file" />
It will work as__


Friday, 15 April 2016

how to share your website in Facebook by javascript ?

 
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!-- facebook login -->
<script>
//Load the Facebook JS SDK
     (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {
            return;
        }
        js = d.createElement('script');
        js.id = id;
        js.async = true;
        js.src = "https://connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document)); 
    
    
    /* (function(d, s, id){
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));
 */
// Init the SDK upon load
    window.fbAsyncInit = function () {
        FB.init({
            appId: '1459247121050170',//0
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true, // parse XFBML
            version: 'v2.5' // old  v2.4
        });


// Specify the extended permissions needed to view user data
// The user will be asked to grant these permissions to the app (so only pick those that are needed)
//public_profile,email
        var permissions = [
            'public_profile',
            'email',
        ].join(',');

        var fields = [
            'id',
            'name',
            'first_name',
            'middle_name',
            'last_name',
            'gender',
            'locale',
            'languages',
            'link',
            'third_party_id',
            'installed',
            'timezone',
            'updated_time',
            'verified',
            'age_range',
            'bio',
            'birthday',
            'cover',
            'currency',
            'devices',
            'education',
            'email',
            'hometown',
            'interested_in',
            'location',
            'political',
            'payment_pricepoints',
            'favorite_athletes',
            'favorite_teams',
            'picture',
            'quotes',
            'relationship_status',
            'religion',
            'significant_other',
            'video_upload_limits',
            'website',
            'work'
        ].join(',');

        function showDetails() {
            FB.api('/me', {fields: fields}, function (details) {

                alert(JSON.stringify(details));  // display all the details

                var res = jQuery.parseJSON(JSON.stringify(details));
                /* alert(res.payment_pricepoints.mobile.length);
     for(var i=0;i<res.payment_pricepoints.mobile.length;i++){   
      alert(res.payment_pricepoints.mobile[i].local_currency);
     } */
                var email = res.email;
                var firstName = res.first_name;
                var lastName = res.last_name;
                var gender = res.gender;
                var profielPictureURL = res.picture.data.url;
                //alert(profielPictureURL);

                profielPictureURL = profielPictureURL.replace(/&/g, "@");
                //alert(profielPictureURL);

                var data = "email=" + email + "&firstName=" + firstName + "&lastName=" + lastName + "&gender=" + gender + "&profielPictureURL=" + profielPictureURL + "&operation=social-media-signin&siginThrough=facebook";
                alert(data);
             /*    $.ajax({
                    type: "POST",
                    url: "LoginServlet",
                    data: data,
                    success: function (response) {
                        if (response === "0") {
                            alert("Invalid Login");
                        } else {
                            location.href = "";
                        }
                    },
                    error: function (errorMsg) {
                        alert("Error Occurred.");
                    }

                }); */

            });
        }
   


        $('#facebook').click(function () {
            //initiate OAuth Login
            FB.login(function (response) {
                // if login was successful, execute the following code
                if (response.authResponse) {
                    showDetails();
                    sharefbimage();
                }
            }, {scope: "public_profile,email"});
        });


       

        
    };
    
    //todayscode......................
    function sharefbimage() {
  FB.init({ appId: '1459247121050170', status: true, cookie: true });
  FB.ui(
  {
              method: 'share',
              name: 'Facebook Dialogs',
              href: $(location).attr('href'),
              link: 'www.plateofcode.com',
              picture: 'https://www.blogger.com/img/blogger-logo-small.png',
              caption: ' Book',
              description: 'description'
          },
          function (response) {
           alert(JSON.stringify(response));
              if (response && response.post_id) {
                  alert('success');
              } else {
                 alert('error');
              }
          }
        );
    }
    //

</script>

<!-- end facebook login -->



</head>
<body>
<button id="facebook" style="background-color: #0967DA;color:white;border: thin;">facebook</button>

</body>
</html>
 
















It will work as....


Thursday, 7 April 2016

How to find Longitude and Latitude of an area by provideing City name,State Name or PIN code Using Google API ?

 
   <html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Geocoding service</title>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
        function codeAddress() {
        var address = document.getElementById("address").value;
        var geocoder = new google.maps.Geocoder();

        geocoder.geocode( { 'address': address}, function(results, status) {
          var location = results[0].geometry.location;
          alert('LAT: ' + location.lat() + ' LANG: ' + location.lng());
    loadMap(location.lat(),location.lng())
        });
        }
        google.maps.event.addDomListener(window, 'load', codeAddress);
  
   function loadMap(longi,lati) {
   
            var mapOptions = {
               center:new google.maps.LatLng(longi,lati),
               zoom:7
            }
    
  var map = new google.maps.Map(document.getElementById("sample"),mapOptions);
            
            var marker = new google.maps.Marker({
               position: new google.maps.LatLng(longi,lati),
               map: map,
            });
         }
    </script>
  </head>
  <body>
    <div id="panel">
      <input id="address" type="textbox" value="Bhadrak">
      <input type="button" value="Geocode" onclick="codeAddress()">
    </div>
  <div id = "sample" style = "width:580px; height:400px;"></div>
  </body>
</html>
 

It will work as..



  
    
    
    Geocoding service
    
    
  
  
    

Tuesday, 5 April 2016

how Trace root server IP in Java

       


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class NetworkDiagnostics{
  private final String os = System.getProperty("os.name").toLowerCase();

  public String traceRoute(InetAddress address){
    String route = "";
    try {
        Process traceRt;
        if(os.contains("win")) traceRt = Runtime.getRuntime().exec("tracert " + address.getHostAddress());
        else traceRt = Runtime.getRuntime().exec("traceroute " + address.getHostAddress());

        // read the output from the command
        route = convertStreamToString(traceRt.getInputStream());

        // read any errors from the attempted command
        String errors = convertStreamToString(traceRt.getErrorStream());
       
    }
    catch (IOException e) {
        
    }

    return route;
}

private String convertStreamToString(InputStream inputStream) {
 BufferedReader bf=new BufferedReader(new InputStreamReader(inputStream));
 String line="";
 try {
  while((line=bf.readLine())!=null){
   System.out.println(line);
  }
 } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return null;
}

public static void main(String args[]){
 try {
  InetAddress ip=InetAddress.getByName(args[0]);
  NetworkDiagnostics networkDiagnostics=new NetworkDiagnostics();
  networkDiagnostics.traceRoute(ip);
  
  
 } catch (UnknownHostException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
}
}

 

Compile it as >javac NetworkDiagnostics.java
 Run it as   >java NetworkDiagnostics example.com

It will show like.........

Trace Location by longitude and latitude in HTML using google API..!!


<!DOCTYPE html>
<html>
   
   <head>
      <script src = "http://maps.googleapis.com/maps/api/js"></script>
      
      <script>
         function loadMap(longi,lati) {
   
            var mapOptions = {
               center:new google.maps.LatLng(longi,lati),
               zoom:7
            }
    
  var map = new google.maps.Map(document.getElementById("sample"),mapOptions);
            
            var marker = new google.maps.Marker({
               position: new google.maps.LatLng(longi,lati),
               map: map,
            });
         }
      </script>
      
   </head>
   
   <body >
   <form onsubmit="return false;">
   <input type="text" placeholder="longitude" id="longi">
   <input type="text" placeholder="latitude" id="lati">
   <input type="button" onclick="loadMap(document.getElementById('longi').value,
     document.getElementById('lati').value)" value="TracertLocation"> 
   </form>
      <div id = "sample" style = "width:580px; height:400px;"></div>
   </body>
   
</html>


It will Work as..!!!!