Friday, November 2, 2012

Reset Lost/Forgotten root password for MySQL

The following are the steos to restore MySQL root password that is lost/forgotten.

Step 1: Stop MySQL daemon if it is currently running    
     Command to find the MySQL Pid and kill the MySQL process
                ps –ax|grep mysql
                kill -9 pid
Step 2: Run MySQL safe daemon with skipping grant tables
                 mysqld_safe --skip-grant-tables & 
Step 3: Login to MySQL as root with no password
                 mysql -u root mysql
Step 4: Run UPDATE query to reset the root password
          UPDATE user SET password=PASSWORD("ualue=42") WHERE user="root";
      FLUSH PRIVILEGES; 
Step 5: Stop MySQL safe daemon
         Command to find the MySQL safe daemon Pid and kill the MySQL process
               ps –ax|grep mysqld_safe
               kill -9 pid
Step 6: Start MySQL
                            /etc/init.d/mysql start
Step 7: Login into MySQL using root password                          
                           mysql -uroot -proot
 

Thursday, August 16, 2012

Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules”


    While Adding/Removing the projects in tomcat server from eclipse , I am getting issue as “ Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules”. We are unable to add the project in server.
Its occuring since mismatch of jst version.

  

Solution

In project, “.settings” folder, find this file “org.eclipse.wst.common.project.facet.core.xml“, change the version of facet="jst.web" to 2.4 or 2.5.
File : org.eclipse.wst.common.project.facet.core.xml



<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.6"/>
<installed facet="jst.web" version="2.5"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>



"There are no resources that can be added or removed from the server eclipse tomcat"


      I have created the Appfuse project . Its running fine in maven jetty server. I would like to run this project in tomcat server. I have added the tomcat server in eclipse and I have tried by right clicking tomcat server and Add remove..., it says "There is no resources that can be added or removed from the server".

Solution:

      I think eclipse is not recognizing our project as a Dynamic Web Application.
I have followed the following steps for fixing this issue.

    Select Project ==> Properties ==> Project Facets and make sure Dynamic Web Module check box is checked


 

Monday, July 30, 2012

org.codehaus.mojo:buildnumber-maven-plugin:maven-plugin:1.0-beta-1-SNAPSHOT - ubuntu 11.10

      A required plugin was not found: Plugin could not be found - check that the goal name is correct: Unable to download the artifact from any repository

    org.codehaus.mojo:buildnumber-maven-plugin:maven-plugin:1.0-beta-1-SNAPSHOT

Problem:

       if ubuntu and Ant tool version is mismatch, we could not download the maven repository.

Solution:

          Use the following latest Ant dependency version and try.
       <dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.8.2</version>
<scope>compile</scope>
</dependency>

 

libglib2.0-0 : Breaks: gnome-control-center (< 1:3) but 1:2.32.1-0ubuntu15 is to be installed E: Broken packages

    I got the following error while installing mysql-server in ubuntu 11 version

   The following packages have unmet dependencies:  libglib2.0-0 : Breaks: gnome-control-center (< 1:3) but 1:2.32.1-0ubuntu15 is to be installed E: Broken packages

Solution:
    
         sudo apt-get install gnome-control-center

Wednesday, July 25, 2012

Tamil Font support in Google Chrome Browser in ubuntu.

Go to freefont directory
  cd /usr/share/fonts/truetype/freefont/

Remove the following fonts

  rm -rf FreeSans.ttf
  rm -rf FreeSerif.ttf

Monday, July 23, 2012

(13)Permission denied: make_sock: could not bind to address

   In apache, this type of error occurs at the time of starting the service after editing the httpd.conf file to listen to a particular port number. The reason is apache allows only specified http port numbers, and the one you have given is not available in http port list

   We can check the http port list whether our port is available or not using the command given below.

semanage port -l|grep http

If the port number is not in the list (ex: 4080), add by using,
semanage port -a -t http_port_t -p tcp 4080


Now restart apache.

Stored Procedure for reading data from CSV file

    The following are the sample Stored Procedure for reading the data from CSV file and insert into database table.

    DELIMITER //
DROP PROCEDURE IF EXISTS `CHECKSERIALNUMBER`;
DROP TABLE IF EXISTS `SERIAL_NUMBER_TEMP_TABLE`;
CREATE TABLE `SP_TEST`.`SERIAL_NUMBER_TEMP_TABLE`(`ID` INT(5) NOT NULL ,`SERIAL_NUMBER` VARCHAR(255));
LOAD DATA LOCAL INFILE '/home/eswar/file.csv' INTO TABLE `SP_TEST`.`SERIAL_NUMBER_TEMP_TABLE`
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n' IGNORE 1 LINES;
CREATE PROCEDURE `CHECKSERIALNUMBER`()
BEGIN
DECLARE _COUNT INT;
DECLARE _I INT DEFAULT 1;
DECLARE _SNO VARCHAR(255);
DECLARE _SNOEXIST VARCHAR(255);
SELECT COUNT(*) INTO _COUNT FROM `SERIAL_NUMBER_TEMP_TABLE`;
WHILE _COUNT >= _I DO
SELECT `SERIAL_NUMBER` INTO _SNO FROM `SERIAL_NUMBER_TEMP_TABLE` WHERE ID=_I;
SELECT `SERIAL_NUMBER` INTO _SNOEXIST FROM `RT_TEST__TABLE` WHERE `SERIAL_NUMBER`=_SNO;
IF _SNOEXIST IS NULL THEN
SELECT _SNO,'Not Exist';
ELSE
SELECT _SNO,'Exist';
END IF;
SET _I=_I+1;
SET _SNOEXIST = null;
END WHILE;
END //
DELIMITER ; 



Friday, July 20, 2012

"Please enter your secure storage password" in Eclipse Helios.

      This alert prompt will be appearing and killing us while installing any plugin in eclipse.
if we forgot the password then no need to explain the situation. To get rid from this we have to disable completely the secure storage password of Eclipse Helios

need to delete this folder from home directory and restart the eclipse:

    ../.eclipse/org.eclipse.equinox.security


Tuesday, July 17, 2012

Upload a file in a single click using jQuery as in gmail attachement

In older days, user wants to browse the button, choose the file and click the upload button for attaching the file.

Nowadays user does not like more mouse click operation. They all are would like to perform all operations within a single click.

The following jquery script is used to upload a file in single click.


<a id='uploader' href='javascript:void(0)'>Add Attachment</a>

   upclick(
     {
      element: uploader,
      action: '/file/fileUpload.action?method=fileUpload,
      dataname:'upload',
      oncomplete:
        function(response_data)
        {
            alert('Data has been sent successfully');
        }
     });
 }


* note: Have to include the attached js file

Monday, July 16, 2012

Problem in compiling and installing a simple maven project

While running “mvn install” We may receive the following error:

Error installing artifact's metadata: Error installing metadata:
Error updating group repository metadata
input contained no data


Reason:


      The problem here was an empty/corrupted maven-metadata-local.xml in our local repository of the artifact wanted to install.


Solution:

   Find the maven-metadata-local.xml using below given command

   sudo find / -name maven-metadata-local.xml -empty -print


   Remove the file maven-metadata-local.xml from that location and run "mvn install". This will work perfectly.

Wednesday, July 4, 2012

Move the Screen to next page by swiping on screen Using jQuery touch Swipe: iPad/iPhone


    The screen is designed by jquery will be used in iPad and iPhone applications.
If we use click event in iPad/iPhone, It will look ugly.It might not give the iPad application feel.
This post will help us to implement the swipe feature iPad using jquery touch swipe.

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
String contextPath = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/13339/patientportal/jquery.touchSwipe.js"></script>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<script>
var ua = navigator.userAgent;
var isiPad = /iPad/i.test(ua) || /iPhone OS 3_1_2/i.test(ua) || /iPhone OS 3_2_2/i.test(ua);
//if(isiPad){
var swipeOptions=
{
swipe:swipe,
threshold:0
}
$(function()
{
//Enable swiping...
$("#commonprofile").swipe( swipeOptions );
});
//}
//Swipe handlers.
//The only arg passed is the original touch event object
function swipe(event, direction)
{
var tc = document.getElementById("tabs");
var ary = tc ? tc.getElementsByTagName("a") : [];
var id = $("li.active").attr("id");
if(direction=='left' && id < 5){
id++;
var url = ary[id].href.split("4080");
window.location.href = url[1];
}else if(direction=='right' && id > 0){
id--;
var url = ary[id].href.split("4080");
window.location.href = url[1];
}
}
</script>
<body style="background-color:#323232;margin:0px">
<div id="tabs" class="tab">
<ul class="tabs">
<li id="0" class="active"><a href="/patientportal/profileDetails.action"
style="color: #0B5D95;">Profile</a></li>
<li id="1" ><a href="/patientportal/patientClinicalDetails.action">Clinical</a>
</li>
<li id="2"><a href="/patientportal/patientMedicalDetails.action">Medication</a>
</li>
<li id="3"><a href="/patientportal/patientInvestigationDetails.action">Lab Result</a></li>
<li id="4"><a href="/patientportal/patientAllergyDetails.action">Allergies</a>
</li>
</ul>
<div id="commonprofile">
<div id="profile" align="left" class="tab_container"><%= request.getAttribute("treatmentSummaryProfile") %>
</div>
</div>
</div>
</body>
</html>


Download Path:
   You can down load the jquery.touchSwipe.js from below given url.
     https://github.com/mattbryson/TouchSwipe-Jquery-Plugin
If you add, above downloaded file the scrolling and zooming will not work.
you have to modify the below given changes.

    1. Open the downloaded js file.
    2. Search for the function init(options)  and
    3.  Replace

     if (options && (options.allowPageScroll==undefined && (options.swipe!=undefined || options.swipeStatus!=undefined)))
            options.allowPageScroll=NONE;

 by
    if (options)
            options.allowPageScroll=AUTO;

   

Monday, July 2, 2012

Sample Java Program for Implementing Singleton.


package com.test;

public class MainTest {
public static void main(String[] args) {
SingletonsTest test = SingletonsTest.getInstance();
SingletonsTest test2 = SingletonsTest.getInstance();
// SingletonTest tss = new SingletonTest();
}
}

class SingletonsTest{
private static SingletonsTest uniqTest;
private SingletonsTest(){
}
public static synchronized SingletonsTest getInstance(){
if(uniqTest == null){
System.out.println("New instances are created====");
uniqTest = new SingletonsTest();
}
return uniqTest;
}
}

Multiple row insert in sql server from java


We can insert the multiple rows into sql server from java using the statement.executeBatch()
function. The sample program for inserting the multiple rows are given below.

package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class MultipleRowUpdateTest {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/portal","root", "root");
Statement stmt = conn.createStatement();
stmt.addBatch("INSERT INTO role " +
"VALUES(5,'temp5','ROLE_ESWAR5')");
stmt.addBatch("INSERT INTO role " +
"VALUES(6, 'temp3','ROLE_ESWAR2')");
stmt.addBatch("INSERT INTO role " +
"VALUES(7, 'temp4','ROLE_ESWAR3')");
stmt.executeBatch();
}catch (Exception e) {
e.printStackTrace();
}
}
}

Thursday, June 28, 2012

Sample Program for Comparable and Comparator


Comparator and Comparable in Java are two of fundamental interface of Java API which is very important to understand to implement sorting in Java. It’s often required to sort objects stored in any collection class or in Array and that time .

Comparable:

A comparable object is capable of comparing itself with another object. The class itself must implements the java.lang.Comparable interface in order to be able to compare its instances.
java.lang.Comparable: int compareTo(Object o1)
This method compares this object with o1 object. Returned int value has the following meanings.
        1. positive – this object is greater than o1
        2. negative – this object is less than o1
        3. Zero – this object equals to o1
java.util.Collections.sort(List) and java.util.Arrays.sort(Object[]) methods can be used to sort using natural ordering of objects.


Sample Code:
package com.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SortingObjectList {
public static void main(String[] args) {
Employee emp1 = new Employee();
emp1.setAge(12);
emp1.setFirstName("Eswar");
emp1.setLastName("Palani");
emp1.setEmpId(13);
List<Employee> sortList = new ArrayList<Employee>();
sortList.add(emp1);
Employee emp2 = new Employee();
emp2.setAge(34);
emp2.setEmpId(15);
emp2.setFirstName("Karthi");
emp2.setLastName("Palani");
sortList.add(emp2);
Employee emp3 = new Employee();
emp3.setAge(50);
emp3.setEmpId(15);
emp3.setFirstName("Aru");
emp3.setLastName("Palani");
sortList.add(emp3);
Collections.sort(sortList);
System.out.println("The sorted lists are======>");
for (Employee employee : sortList) {
System.out.println(employee.getFirstName()+" "+employee.getLastName());
}
}

}

class Employee implements Comparable<Employee>{
private String firstName;
private String lastName;
private int age;
private int empId;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public int compareTo(Employee o) {
if (o.firstName.equals(this.firstName))
if (o.age-this.age == 0)
return o.empId - this.empId;
else
return o.age-this.age;
else
return o.firstName.compareTo(this.firstName);
}
}

Output:
The sorted lists are======>
Karthi Palani
Eswar Palani
Aru Palani

Comparator

A comparator object is capable of comparing two different objects. The class is not comparing its instances, but some other class’s instances. This comparator class must implement the java.util.Comparator interface.
java.util.Comparator: int compare(Object o1, Objecto2)
This method compares o1 and o2 objects. Returned int value has the following meanings.
          1. positive – this object is greater than o1
          2. negative – this object is less than o1
          3. Zero – this object equals to o1
java.util.Collections.sort(List, Comparator) and java.util.Arrays.sort(Object[], Comparator) methods can be used if a Comparator is available for comparison.

Sample Code:


package com.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortingObjectListComparator {

public static void main(String[] args) {
Staff emp1 = new Staff();
emp1.setAge(12);
emp1.setFirstName("Eswar");
emp1.setLastName("Palani");
emp1.setEmpId(13);
List<Staff> sortList = new ArrayList<Staff>();
sortList.add(emp1);
Staff emp2 = new Staff();
emp2.setAge(34);
emp2.setEmpId(15);
emp2.setFirstName("Karthi");
emp2.setLastName("Palani");
sortList.add(emp2);
Staff emp3 = new Staff();
emp3.setAge(50);
emp3.setEmpId(15);
emp3.setFirstName("Aru");
emp3.setLastName("Palani");
sortList.add(emp3);
Collections.sort(sortList, new Staff());
System.out.println("The sorted lists are===");
for (Staff staff : sortList) {
System.out.println(staff.getFirstName()+" "+staff.getLastName());
}
}

}


class Staff implements Comparator<Staff>{
private String firstName;
private String lastName;
private int age;
private int empId;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public int compare(Staff o1, Staff o2) {
return o1.getFirstName().compareTo(o2.getFirstName());
}
}

output:

The sorted lists are===
Aru Palani
Eswar Palani
Karthi Palani



Difference between Comparator and Comparable:

1) Comparator in Java is defined in java.util package while Comparable interface in Java is defined in java.lang package.

2) Comparator interface in Java has method public int compare (Object o1, Object o2) which returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. While Comparable interface has method public int compareTo(Object o) which returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

3) If you see then logical difference between these two is Comparator in Java compare two objects provided to him, while Comparable interface compares "this" reference with the object specified.

4) Comparable in Java is used to implement natural ordering of object. In Java API String, Date and wrapper classes implement Comparable interface.

5) If any class implement Comparable interface in Java then collection of that object either List or Array can be sorted automatically by using  Collections.sort() or Arrays.sort() method and object will be sorted based on there natural order defined by CompareTo method.

6)Objects which implement Comparable in Java  can be used as keys in a sorted map or elements in a sorted set for example TreeSet, without specifying any Comparator.