Posts

Showing posts from December, 2011

Get real client ip-address using java / getRemoteAddr() is giving 127.0.0.1 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 127.0.0.1 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;
 try{
   Class.forName("com.mysql.jdbc.Driver");
   con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/DATABASENAME","userName","password");
   try{
      String sql = "SELECT * FROM employee WHERE salary >= ?";
      preparedStatement = con.prepareStatement(sql);
      preparedStatement.setInt(1,10000);
      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) {
         continue;
      }
      tdText = cells[0].innerHTML;  // For 0th td for each tr of this table....
      alert(tdText);    
    }
}

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.
com.restfb.BaseFacebookClient$DefaultLegacyFacebookExceptionMapper.exceptionForTypeAndMessage(BaseFacebookClient.java:147)
com.restfb.BaseFacebookClient.throwLegacyFacebookResponseStatusExceptionIfNecessary(BaseFacebookClient.java:208)
com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:523)
com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:485)
com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:445)
com.restfb.DefaultFacebookClient.executeQuery(DefaultFacebookClient.java:366)
com.vicwalks.web.util.SocialMediaUtil.findFacebookFriendsUsingRest(SocialMediaUtil.java:84)
com.vicwalks.web.action.FacebookConnectAction.execute(FacebookConnectAction.java:87)
sun.reflect.NativeMethodAccessorImp…

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());
    myFacebookFri…

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 http://code.google.com/android/add-ons/google-apis/mapkey.html#getdebugfingerprint



Android: MapActivity is not found

Image
MapActivity is a special sub-class of android.app.Activity. 


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... http://knowledge-serve.blogspot.com/2011/12/android-mapactivity-can-not-be-resolved.html