Follow your thought and motivation..!!!

March 19, 2013 Leave a comment

At times at a plain simple moment in the life one may come to a situation where there are fears (of people, situations, outcomes and time) which may limit one to proceed or decelerate. The fears are best tackled by these things i believe:

  • Don’t run away from them
  • Convince yourself in a logical (whatever is a comfortable logic to you) about the minuteness and invaluable nature of the fears
  • Learn that you are you and no one others opinion or advice suits you (most of them are just critics) other than your own motivation, thoughts and love for your work or whatever.

Try to be yourself, the Simple Plain YOU and forget rest because you are unique and so is your work, thoughts, ideas, approach to do things, motivations, priorities and the way you have traveled so long to get where you are today.
Life starts becoming so simple and charming when you start becoming YOU and following your thought and motivation..

Categories: Life

Validate you JSON

March 4, 2013 Leave a comment

This is a great online utility for validating your JSON.
Catch it on this link: http://jsonlint.com/

Generating an overly Complex String :)

February 13, 2013 Leave a comment

This is how i generated an overly “complex” string. There would be surely better implementations but this one works fine for me. 🙂 

package com.intuira.test;

import java.util.Random;

/**
 * @author Hassan Ali
 */
public class OverlyComplexString {
   
    private static String[] alphabets = {"a", "B", "c", "D", "e", "F", "G", "h", "i", "j", "k", "L", "M", "N", "O", "p", "Q", "r", "S", "T", "u", "v", "W", "x", "Y", "z"};
    private static String[] numerals = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
    private static String[] specialChars = {".", ",", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "+", "=", "_", ":", ";", "'", "\"", "/", "<", ">"};
    private static Random random = new Random();

    
/**
 * returns an overly complex randomly generated String 😉
 */
    private static String getOverlyComplexString(int length) {
        
        StringBuilder overlyComplexString = new StringBuilder();
        
        for(int i=0; i<length; i++) {

            
            switch(random.nextInt(3)) { 
            
                case 0:
                    overlyComplexString.append(alphabets[random.nextInt(alphabets.length)]);
                    break;
                
                case 1:
                    overlyComplexString.append(numerals[random.nextInt(numerals.length)]);
                    break;
                    
                case 2:
                    overlyComplexString.append(specialChars[random.nextInt(specialChars.length)]);
                    break;
                
            }
        
        }
        
        return overlyComplexString.toString();
    }
    
    public static void main(String[] args) { 
    
        System.out.println(getOverlyComplexString(20));
        
    }
    
}
Categories: Java

System.getenv would not work until you restart the IDE (Netbeans)

September 27, 2012 Leave a comment

Today i tried to get the value of a newly created environment variable, I was using Netbeans 7.1 (windows 7), it returned null, however the variable was added. I got to console and executed the program from there, it worked fine. It took me an hour to find out the problem. The problem was that while netbeans is running and you add a new Environment Variable and then try to get it by using

System.getnv() or System.getenv(String name)

it will return null until you restart your Netbeans. Probably there might be some issue that values are not updated for the Netbeans process, so you have to restart your Netbeans (i’m not sure about Eclipse and others :/). After that you’ll get the value of the newly added environment variable. A quick tip if you are facing the same, restart your netbeans..! 🙂

Categories: Java

Software Development – The Thoughts

leaf graphic I often think about being a software developer. One may compare this with being a painter or an artist. The biggest similarity between them is the “Creativity”. Probably both a software craftsman and a painter or an artist have the same feeling of pleasure when they are somewhere in the depth of the oceans of thought. A painter while running the brushes on the canvas would be feeling much similar to a coder translating the ideas and the feel into the code.
One would feel that he is experiencing a unique sort of relation in which he has some sort of “direct connection” with the Creator. These feelings are more of unexplainable, they cannot be explained in the words. Like one cannot feel what a person feels when he climbs a mountain or is flying a plane unless he himself goes through…

Categories: The thoughts Tags: ,

Connecting to Ms SQL Server 2005 using JDBC in Windows Authentication Mode

April 16, 2012 2 comments

Hi All! There are 2 modes of connecting to the Ms SQL Server
1) Windows Authentication Mode
2) SqlServer Authentication Mode

I will be discussing the Windows authentication mode here. Actually i was first using SqlServer authentication mode but that wasn’t required at the deployment site so had to work with Windows Authentication. I am discussing only from implementation point of view.

First you have to download the SqlJdbc 4.0 jar libraries (google it and you’ll find it from Microsoft). You are concerned with following two files in that downloaded SqlJdbc 4.0 folder:

a) sqljdbc4.jar
b) sqljdbc_auth.dll (please note that you will find two sqljdbc_auth.dlls for x86 and x64 so carefully choose according to your platform)

Add both of these in your class path. An important thing is here that if you are using an IDE (like eclipse which i have used here) it may not provide you with an option to add a dll to the path so a Simple Solution for that is to place the dll (sqljdbc_auth.dll) in the your JRE’s bin (i placed it at C:\Program Files\Java\jre6\bin).

Now when the configurations are done lets come to the code.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class SqlServerConnect {

	/**
	 * @author Hassan Ali
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */

	public SqlServerConnect() throws ClassNotFoundException, SQLException {
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		Connection connection = DriverManager
				.getConnection("jdbc:sqlserver://localhost:1433;database=BioStar;integratedSecurity=true;");
		System.out
				.println("Connected to MS SQL 2005 using windows authentication");
	}

	public static void main(String[] args) throws ClassNotFoundException, SQLException {

		new SqlServerConnect();
	}

}

having this working example now i will explain it a bit, i’ll highlight the important points:

a) The Micrsoft JDBC driver for MS SQL server is: com.microsoft.sqlserver.jdbc.SQLServerDriver so loaded it using Class.formName()
b) The Connection String for connecting to MS Sql Server using Windows Authentication Mode is: jdbc:sqlserver://localhost:1433;database=BioStar;integratedSecurity=true;

(Note that using windows authentication you have to give no username or password simply have to mention this additional integratedSecurity=true.)

Simply copying this connection string and using it in you application as far as you change the “database=BioStar” to “database=yourDbName” would be working.
In windows authentication you don’t need to mention user name and password for connecting is because you are connecting as a windows user to your MS Sql Server instance.

I only tried to mention some important points relating the connection string and sqljdbc_auth.dll etc things because people (i too) get more confused and irritated on such issues. Any questions or comments are always welcomed. Cheers 🙂

Categories: Java

Validate your XML

February 24, 2012 Leave a comment

Have you ever felt the need to Validate your XML files. Often you would be stuck in a situation where your XML is not a valid one but you don’t know where the mistake is actually. There’s a simple solution online, use the online XML validator by w3c. go to http://validator.w3.org/. Happy validation!