Get free talktime worth 5% of your purchase on any product from Flipkart.com

Get free talktime worth 5% of your purchase on any product from Flipkart.com

*Please use the Flipkart search box on the right side of the screen.

*On click of the desired product, you will be redirected to the Flipkart website.

*Applicable on purchase of products worth Rs. 500 and above only.

*Not Valid on Flipkart e-gift vouchers.

*Recharge will be done only after 30 days from the date of purchase.

*Javadomain or Flipkart will not be liable for Javadomain recharge vouchers on any purchases made directly at flipkart.com

*Standard T&C of Flipkart and Javadomain apply.

For any queries reach out at Sivachudar@javadomain.in (or) Naveen@javadomain.in

Increasing the console size in eclipse

Increasing the console size in eclipse

Windows -> Preferences -> Run/Debug -> Console

Limit console output (check)

Then increase the size in the console buffer size textbox.

Note: 1000000 (around 1MB of text) is the max one in many of the eclipse version.

console size eclipse

Feel free to share your comments/feedbacks……

Hibernate Criteria Duplicate Records Issue [Solved]

Hibernate_criteria_duplicate_records_issue_resolved

Hibernate Criteria Duplicate Records Issue:
Problem:
Duplicate same records with hibernate join.

In Hibernate if we did join, we may get duplicates sometime.

Below are the possible ways to resolve the duplicate same record value issue,

Possible Solutions:
1. criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
2. criteria.setProjection(Projections.distinct(Projections.property(“id”)));
3. criteria.setProjection(Projections.distinct(Projections.id()));

Recommended Solution:

criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

If nothing is working then change the list to set, so that duplicates will be avoided from java side.

Hibernate Recommended Books:

Feel free to post your comments/feedbacks..

Starting SVN Server in Windows [command]

Here We are considering that you have already created the svn repository.

Below is the command to start the svn server. Once the svn server started only we can access the repository.

SVN Command Syntax:

svnserve -d -r REPO_PATH

If svn repository created in D:/SVN_REPO, then you have to run the below command

SVN Command Example:

svnserve -d -r "D:/SVN_REPO"

Feel free to post your comments and queries.

jQuery Form Validation Example

jQuery Form Validation Example:

We used to validate the form using javascript and there we have to write our own logics to validate the email, phone number and mandatory fields etc….

But now jquery validate plugin is available for ease of form validations.

Include the below scripts:

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>

Form need to be validated:

<form method="post" action="signup.php?retrun=http://www.gururecharge.chudar.com/terms.php"  id="validate_form" name="validate_form">
<div class="divmain" style="  float:left; margin-left:45px; border-right:thin ridge; padding-right:30px;  ">
  <div style="border-bottom:#CCC  solid 1px;"></div>
 <br />
  <div class="divbox1">
    <div class="divbox11">
   <div style="padding:12px 0px 6px 0px;">Enter your full name</div>
   <input type="text" name="usr_name" id="usr_name">
     <div id="disp3"></div>
<div style="padding-bottom:6px;">Enter your Mobile Number</div>
<div class="countryCode">
<input type="text" name="mobileno" id="mobileno" maxlength="10">
<span style="color:#F00;display:none;" id="rvEVMN">Please insert Valid Mobile no</span>
</div>	
<div id="disp"></div>
<div style="padding:12px 0px 6px 0px;">Enter your Email ID</div>
     <input type="text" name="email" id="email">
     <div id="disp1"></div>
 <div style="padding:12px 0px 6px 0px;">Create your Password</div>
     <input type="password" name="password" id="password">
     <div style="clear:both;"></div>
    <div align="right" style="padding-right:90px; padding-top:10px; padding-bottom:10px;">
    </div>
    <div class="btn-spinner" alt="Proceed to Recharge"><div class="spinner hidden"></div>
    <input type="submit" class="btn proceed active" data-express-text="Recharge Now" data-soft-block-text="Proceed anyway" data-default-text="Proceed" name="Proceed" value="Create Account" alt="Proceed to Recharge" ></div>   
    </div>    
  </div>
  <div style="clear:both;"></div>
</div>
</form>

Script to validate the form:

<script>
  $(function() {	  
  // form name
	$("#validate_form").validate({    
		rules: {
			mobileno: 
			{
			required: true,
			number: true,
			minlength: 10,
			maxlength:10,
			},
            email:  {
				required: true,
				email: true,
			},
			password: 
			{
				required: true,
				minlength: 6,
			},
			usr_name:
				{
				required: true,
			},
			},
        // Specify the validation error messages
		messages: {
			mobileno: "Mobile no is mandatory",
			email:  "Email is mandatory",
            password:  "Password is mandatory",
            usr_name:  "Name is mandatory",
        },
        submitHandler: function(form) {
         if($("#mobileno").val() > 0) {   form.submit(); } else {
	document.getElementById('rvEVMN').style.display='inline';		 return false;
			 }
        }
    });
  });
  </script>

Complete source code:

 <html>
<head>
<title>
jQuery Form validation Example
</title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<script>
  $(function() {	  
  // form name
	$("#validate_form").validate({    
		rules: {
			mobileno: 
			{
			required: true,
			number: true,
			minlength: 10,
			maxlength:10,
			},
            email:  {
				required: true,
				email: true,
			},
			password: 
			{
				required: true,
				minlength: 6,
			},
			usr_name:
				{
				required: true,
			},
			},
        // Specify the validation error messages
		messages: {
			mobileno: "Mobile no is mandatory",
			email:  "Email is mandatory",
            password:  "Password is mandatory",
            usr_name:  "Name is mandatory",
        },
        submitHandler: function(form) {
         if($("#mobileno").val() > 0) {   form.submit(); } else {
	document.getElementById('rvEVMN').style.display='inline';		 return false;
			 }
        }
    });
  });
  </script>
<form method="post" action="signup.php?retrun=http://www.gururecharge.chudar.com/terms.php"  id="validate_form" name="validate_form">
<div class="divmain" style="  float:left; margin-left:45px; border-right:thin ridge; padding-right:30px;  ">
  <div style="border-bottom:#CCC  solid 1px;"></div>
 <br />
  <div class="divbox1">
    <div class="divbox11">
   <div style="padding:12px 0px 6px 0px;">Enter your full name</div>
   <input type="text" name="usr_name" id="usr_name">
     <div id="disp3"></div>
<div style="padding-bottom:6px;">Enter your Mobile Number</div>
<div class="countryCode">
<input type="text" name="mobileno" id="mobileno" maxlength="10">
<span style="color:#F00;display:none;" id="rvEVMN">Please insert Valid Mobile no</span>
</div>	
<div id="disp"></div>
<div style="padding:12px 0px 6px 0px;">Enter your Email ID</div>
     <input type="text" name="email" id="email">
     <div id="disp1"></div>
 <div style="padding:12px 0px 6px 0px;">Create your Password</div>
     <input type="password" name="password" id="password">
     <div style="clear:both;"></div>
    <div align="right" style="padding-right:90px; padding-top:10px; padding-bottom:10px;">
    </div>
    <div class="btn-spinner" alt="Proceed to Recharge"><div class="spinner hidden"></div>
    <input type="submit" class="btn proceed active" data-express-text="Recharge Now" data-soft-block-text="Proceed anyway" data-default-text="Proceed" name="Proceed" value="Create Account" alt="Proceed to Recharge" ></div>   
    </div>    
  </div>
  <div style="clear:both;"></div>
</div>
</form>
</body>
</html>

This will work this way,
Form to validate using jQuery

And validation worked this way,
validated form

Download Source code:

jQuery Form Validation Example

Recommended jQuery Books:

How to use property file in php ?

How to use property file in php ?

What is Property file ?
Property file in php will have the .ini extension. which will be used generally for the constant informations like website_url, filepaths and key, value mappings etc.

Extension:
Its a .ini extension.

Sample Property file:

prop.ini:

Idea=12
Airtel=2
Aircel=1

(or)

Idea=12;
Airtel=2;
Aircel=1;

PHP Code to get the prop(ini file) values by its key:

<?php
$ini_array = parse_ini_file("prop.ini");
$propKey = 'Idea';
echo $ini_array[$propKey];
?>

Output:
12

Download Source code:
Php Property File Source code

Please feel free to post your queries/comments…..

Php Recommended Books:

Removing Featured Image from post and search result wordpress [Solved]

Removing Featured Image from post and search result wordpress:

1. Comment the below snippet from the single.php (in some themes file names may vary. (vantage theme -> content-single.php))

<!-- <?php if( has_post_thumbnail() && siteorigin_setting('blog_featured_image') ): ?>
<div class="entry-thumbnail"><?php the_post_thumbnail( is_active_sidebar('sidebar-1') ? 'post-thumbnail' : 'vantage-thumbnail-no-sidebar' ) ?></div>
<?php endif; ?>
-->

If you comment the above snippet, it will remove the thumbnail or featured image only from the post. But still it will exist in the post search page.

2. Comment the below snippet from the search.php (in some themes file name may vary)

Search under entry-header section then comment the below lines, then it will not be displayed even in post search page.

<!--  <?php if( has_post_thumbnail() && siteorigin_setting('blog_featured_image_type') == 'large' ): ?>
<div class="entry-thumbnail">
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( is_active_sidebar('sidebar-1') ? 'post-thumbnail' : 'vantage-thumbnail-no-sidebar' ) ?></a>
</div>
<?php endif; ?>
-->

Feel free to comment/provide some other solutions….

PHP Recommended Books:

How to use conditional breakpoint in eclipse (step by step)

We can say no developers in the world who developing without debugging his/her code. We have lot of debugging options to make use the debugging option more effectively.

Here we are going to see how we can debug with conditional breakpoints.
Step 1:
Below is the very simple program to explain the conditional breakpoint,

package in.javadomain;
public class ConditionalBreakpoint {
	public static void main(String[] args) {
		boolean value = false;
		value=true;
		System.out.println("Debug, if condition given in the breakpoint condition satisfies ");
	}

}

Step 2:
Put the breakpoint in the sysout line of the above program.

Step 3:
Right click on the breakpoint and click breakpoint properties (or) control+double click on the breakpoint, then click the Breakpoint properties -> Enable the Conditional checkbox -> click suspend when true radio button.
Then add the condition,
setting breakpoint

Now Run as debug and see the output for both the conditions (value==false and value==true) below,

when value==true
conditional breakpoint

when value==false
conditional_breakpoint_false

Note:
After changing the breakpoint conditions, ensure you have saved it.

Recommended Java Books:

Main Method auto generation in java Eclipse example

As we know main method is first method java begins its execution. That main method we can generate using two ways in eclipse
Way 1:

While creating the class, we can enable the “public static main method(String[] args) checkbox”,

AutoGenCreate

Way 2:

If we have created the class without enabling the checkbox, then no need to delete and create it again. We can simply create simply typing main with ctrl+shift.

AutoGenCtrlShift

Recommended Books:

Java With MySQL Insert Example

Download the users_test table:
Users_test table – Mysql download

Loading the Mysql connection:

	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

Fetching the records: [Select]

	public void insertUsers(Connection conn, String email,String full_name,String mobile,String pass,String access){
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		System.out.println("Insertion Done!");
	}

Java with Mysql Insert Full Program:

package in.javadomain;

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

/**
 * @author Naveen class to connect java with mysql and fetching mysql records
 *         using java
 */
public class JavaMySQL {
	/**
	 * Main method first get the mysql connection then it will fetch the records
	 */
	public static void main(String[] args) {
		String email = "me@javadomain.in";
		String full_name = "naveenkumar";
		String mobile = "9597470873";
		String pass = "testpass";
		String access = "1";
		JavaMySQL javaMySQL = new JavaMySQL();
		// Getting the mysql Connection
		Connection conn = javaMySQL.LoadDriver();
		// Fetching the mysql table records
		javaMySQL.insertUsers(conn, email, full_name, mobile, pass, access);
	}

	/**
	 * Loads the mysql connection with the given username, password, database
	 * and mysql jar driver
	 * 
	 * @return Connection
	 */
	public Connection LoadDriver() {
		Connection connection = null;
		try {
			// Driver Name
			String mySQLDriver = "org.gjt.mm.mysql.Driver";
			// Path/database name [here guru is the database name]
			String url = "jdbc:mysql://localhost:3306/guru";
			Class.forName(mySQLDriver);
			// User name and password
			connection = DriverManager.getConnection(url, "root", "pass123");

		} catch (Exception exception) {
			System.err.println("Exception! ");
			System.err.println(exception.getMessage());
		}
		return connection;
	}

	/**
	 * @param conn
	 * @param email
	 * @param full_name
	 * @param mobile
	 * @param pass
	 * @param access
	 *            all the above params are inserted using the prepared statement
	 */
	public void insertUsers(Connection conn, String email, String full_name,
			String mobile, String pass, String access) {
		System.out.println("Insert started!");
		String query = " insert into users_test (mobile,email,pass,full_name, access) values (?, ?, ?, ?,?)";
		PreparedStatement preparedStmt;
		try {
			preparedStmt = conn.prepareStatement(query);
			preparedStmt.setString(1, mobile);
			preparedStmt.setString(2, email);
			preparedStmt.setString(3, pass);
			preparedStmt.setString(4, full_name);
			preparedStmt.setString(5, access);
			preparedStmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		System.out.println("Insertion Done!");
	}

}

Output:

Insert started!
Insertion Done!

Download the Source code:
Java With Mysql Insert

Note:
1. Do not forget to add the mysql java connection jar.
2. Mention the username, password and database name correctly.
3. Mention the column names, column name types and table names correctly.

Java Recommended Books:

« Older Entries