Showing posts from December, 2011

Get real client ip-address using java / getRemoteAddr() is giving as client ip address in java

Getting real client ip-address using java (if Apache redirection is used...)
You can use ,
String ipAddress=request.getHeader("X-Forwarded-For");
 if you have configured Apache redirection.

If you will use
 request.getRemoteAddr(), it may return if apache redirection has been configured at your deployment server.

JDBC: Prepared Statement

Prepared Statement Demo using Java/MySQL
package com.vicwalks.web.util;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;

public class PreparedStatementDemo {
 public static void main(String[] args) {
 System.out.println("===========Prepared statement demo===========\n");
 Connection con = null;
 PreparedStatement preparedStatement;
   con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/DATABASENAME","userName","password");
      String sql = "SELECT * FROM employee WHERE salary >= ?";
      preparedStatement = con.prepareStatement(sql);
      ResultSet rs1 = preparedStatement.executeQuery();
      System.out.println("List of employee where salary >…
Get <td> element value inside a <table>

1) Using JQuery.....

$('#tableDivId tr').each(function() {
    var tdText = $(this).find("td:first").html();    

Here you are iterating all rows of a table according to given div id, and then you are fetching first <td> element data for current <tr>....

2) Without JQuery...............

function loadAllTDs(){
var table = document.getElementById('tableDivId'); 
var rows = table.getElementsByTagName('tr');
var cells, tdText;

for (var i = 0, j = rows.length; i < j; ++i) {
      cells = rows[i].getElementsByTagName('td');
      if (!cells.length) {
      tdText = cells[0].innerHTML;  // For 0th td for each tr of this table....

Executing FQL Queries :: FacebookResponseStatusException

com.restfb.exception.FacebookResponseStatusException: Received Facebook error response (code 601): Parser error: SELECT * is not supported.  Please manually list the columns you are interested in.

get facebook friends using restfb

If you are using restfb (Facebook graph API and old REST API client wriiten in Java), and you want to access all friend list after Oauth authentication, you can use following method,

public List<ArrayList> findFacebookFriendsUsingRest(String facebookAccessToken){
  List<ArrayList> myFacebookFriendList= new ArrayList();
  final FacebookClient facebookClient;
  facebookClient = new DefaultFacebookClient(facebookAccessToken);
  User user = facebookClient.fetchObject("me", User.class);
  String userName = user.getFirstName();
  if (userName == null){
userName = user.getLastName();
  String userEmail = user.getEmail();
  com.restfb.Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);
  System.out.println("Count of my friends: " + myFriends.getData().size());
  for(User friend: myFriends.getData()){
System.out.println("Friends id and name: "+friend.getId()+" , "+friend.getName());

Android: MapActivity can not be resolved in android

For Eclipse users:

Please click on Project --> properties-->Resources-->Android--> Select Google api instead of Android

Now click on Ok.

Check again, Project--> properties--> Java build path, see the Libraries tab, expand Google APIs, and see if there is map.jar and android.jar are available or not. They must be.

Now clean your project and then run your project.

Android: where to run keytool command in android

Keytool command can be run at your dos command prompt, if JRE has been set in your  classpath variable.

For example, if you want to get the MD5 Fingerprint of the SDK Debug Certificate for android,

just run the following command...

C:\Documents and Settings\user\.android> keytool -list -alias androiddebugkey  
                                                                -keystore debug.keystore -storepass android -keypass android

where C:\Documents and Settings\user\.android> is the path which consist the debug.keystore that has to be certified.
For detailed information, please visit

Android: MapActivity is not found

MapActivity is a special sub-class of 

If you are using eclipse id, then click on AVD Manager and then it will show you the list of installed as well as un-installed packages. Select Google api packages and click on install. Then you will not this problem. if it is still set java build path

Now if this problem still occurs, see your build path...