Saturday 25 July 2015

Window batch file created folder in current date and copy files.

Windows batch file creating folder in current date as name.

In following example contains the concept for 

1.substring  in batch file
2.comments in batch file
3.creating the folder 
4.for loop 

substring in batch

SET yy=%date:~-4%
 my date is "Sat 07/25/2015 " by using the above code i have cut the "2015" only

Comments
By using  :: i did comments Ref line no 2 author 

my system date format is Sat 07/25/2015  By using substring i have convert into dd-mm-yy

Instruction: Do leave the space between variable declaration and initializing eg. Ref: line no 5-10


@ECHO off
::author bala2e
SET appName=bala2e

SET yy=%date:~-4%
SET mm=%date:~-10,2%
SET dd=%date:~-7,2%
SET MYDATE=%dd%-%mm%-%yy%
SET baseDir=\\192.168.10.88\home\%MYDATE%
SET serverDir=\\192.168.8.202\eGurkha\manager\tomcat\webapps\final
SET appBaseDir=%baseDir%\%appName%
SET controllerDir=%appBaseDir%\controller
SET viewDir=%appBaseDir%\view
SET mkDirectory=(%baseDir% %appBaseDir% %controllerDir% %viewDir%)

FOR %%i IN %mkDirectory% DO MKDIR %%i
SET FILE_LIST=(%serverDir%\reporter\file.jsp %serverDir%\WEB-INF\classes\com\reporter\file.java %serverDir%\WEB-INF\classes\com\db\MsSqlConnect.java %serverDir%\WEB-INF\classes\com\db\OracleConnect.java)

FOR %%i IN %FILE_LIST% DO COPY %%i %baseDir%


COPY "%serverDir%\reporter\scripts\%appName%\*.*" %appBaseDir%
COPY "%serverDir%\reporter\scripts\%appName%\controller\*.*" %controllerDir%
COPY "%serverDir%\reporter\scripts\%appName%\view\*.*" %viewDir%

Tuesday 14 July 2015

How to run sql queries in parallel in java and give response to user Performance increace with select query using thread

How to run SQL Queries simultaneous in java and get response.

The will show you how to run SQL query parallel using java thread and  give response once all finished its execution.

By using below Two java programs .For Reference please see below sql dump. I have used MySQL.

Below link contains all File 


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

/**
 * 
 * @author Bala2e
 *
 */
public class ThreadWithSQL {

 public void runAllThreads() {

  final Connection con = this.getConnection();
  final SQLQuery sqlQuery = new SQLQuery();

  Thread firstQueryThread = new Thread(new Runnable() {
   public void run() {
    sqlQuery.getEmployeeDetails(con);
   }
  });

  Thread secondQueryThread = new Thread(new Runnable() {
   public void run() {
    sqlQuery.getSalesmanDetails(con);

   }
  });
  Thread thridQueryThread = new Thread(new Runnable() {
   public void run() {
    sqlQuery.getClientDetails(con);
   }
  });

  firstQueryThread.start();
  secondQueryThread.start();
  thridQueryThread.start();

  try {
   firstQueryThread.join();
   secondQueryThread.join();
   thridQueryThread.join();

  } catch (Exception e) {
   e.printStackTrace();

  }

  ResultSet rsEmp    = sqlQuery.rsEmp;
  ResultSet rsSales  = sqlQuery.rsSales;
  ResultSet rsClient = sqlQuery.rsclient;

  try {
   
   System.out.println("---------------- Emp Details----------------------");
   while (rsEmp != null && rsEmp.next()) {
    System.out.println("id-" + rsEmp.getString(1) + " name- "+ rsEmp.getString(2));
   }
   
   System.out.println("---------------- Salesman Details----------------------");

   while (rsSales != null && rsSales.next()) {
    System.out.println("id-" + rsSales.getString(1) + "  name- "+ rsSales.getString(2));
      

   }
   System.out.println("---------------- Client Details----------------------");
   while (rsClient != null && rsClient.next()) {
    System.out.println("id-" + rsClient.getString(1) + " name- "+ rsClient.getString(2));

   }
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }

 public Connection getConnection() {
  Connection con = null;
  try {
   Class.forName("com.mysql.jdbc.Driver");
   con = DriverManager.getConnection(
     "jdbc:mysql://localhost:3306/test", "root", "root");
  } catch (Exception e) {
   e.printStackTrace();

  }

  return con;
 }

 public static void main(String[] args) {
  ThreadWithSQL threadWithSQL = new ThreadWithSQL();

  threadWithSQL.runAllThreads();

  // threadWithSQL.runAllThreads();

 }
}


Second Program

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
 * 
 * @author Bala2e
 *
 */
public class SQLQuery {
 ResultSet rsEmp, rsSales, rsclient;

 public void getEmployeeDetails(Connection con) {

  try {
   Statement stmt = con.createStatement();
   rsEmp = stmt.executeQuery("select e.emp_id,e.emp_name from  test.employee e");
     

  } catch (Exception e) {
   e.printStackTrace();
  }
 }

 public void getSalesmanDetails(Connection con) {
  try {
   Statement stmt = con.createStatement();
   rsSales = stmt.executeQuery("select  sm.sales_man_id,sm.name from  test.sales_man sm");
     

  } catch (Exception e) {
   e.printStackTrace();
  }

 }

 public void getClientDetails(Connection con) {

  try {
   Statement stmt = con.createStatement();
   rsclient = stmt.executeQuery("select c.client_id, c.client_name from test.client c");
     

  } catch (Exception e) {
   e.printStackTrace();
  }
 }



Following is the SQL Dump.

CREATE DATABASE  IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `test`;
-- MySQL dump 10.13  Distrib 5.6.17, for Win64 (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version 5.6.21-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `client`
--

DROP TABLE IF EXISTS `client`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `client` (
  `client_id` int(11) NOT NULL,
  `client_name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `client`
--

LOCK TABLES `client` WRITE;
/*!40000 ALTER TABLE `client` DISABLE KEYS */;
INSERT INTO `client` VALUES (1,'murugan store'),(2,'kumar store');
/*!40000 ALTER TABLE `client` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `employee`
--

DROP TABLE IF EXISTS `employee`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `employee` (
  `emp_id` int(11) NOT NULL,
  `emp_name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `employee`
--

LOCK TABLES `employee` WRITE;
/*!40000 ALTER TABLE `employee` DISABLE KEYS */;
INSERT INTO `employee` VALUES (1,'Arun'),(2,'Bala');
/*!40000 ALTER TABLE `employee` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `master_user_details`
--

DROP TABLE IF EXISTS `master_user_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `master_user_details` (
  `user_detail_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` varchar(255) DEFAULT NULL,
  `mobile_no` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`user_detail_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `master_user_details`
--

LOCK TABLES `master_user_details` WRITE;
/*!40000 ALTER TABLE `master_user_details` DISABLE KEYS */;
INSERT INTO `master_user_details` VALUES (1,'B.Balamurugan','27','9042221'),(2,'BALA','27','56565656'),(3,'cc','cccv','vv');
/*!40000 ALTER TABLE `master_user_details` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `sales_man`
--

DROP TABLE IF EXISTS `sales_man`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `sales_man` (
  `sales_man_id` int(11) NOT NULL,
  `name` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`sales_man_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `sales_man`
--

LOCK TABLES `sales_man` WRITE;
/*!40000 ALTER TABLE `sales_man` DISABLE KEYS */;
INSERT INTO `sales_man` VALUES (1,'ajay'),(2,'pinkku');
/*!40000 ALTER TABLE `sales_man` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user_details`
--

DROP TABLE IF EXISTS `user_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_details` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `role_id` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user_details`
--

LOCK TABLES `user_details` WRITE;
/*!40000 ALTER TABLE `user_details` DISABLE KEYS */;
INSERT INTO `user_details` VALUES (1,'bala','bala','1');
/*!40000 ALTER TABLE `user_details` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2015-07-14 23:56:07


Saturday 11 July 2015

Ext JS MVC Pattern ,AJAX Call in Ext JS , Show AJAX Response in grid with Java Servlet

Sencha ‘s Ext JS.

It is the object oriented framework in the base of javascript.
It is used create the web pages with object oriented pattern just like JAVA’S Class method MVC s.
By default it provides many class to create the as input box, combo box etc in page. in its API  
It provides methods for the default and customs validation and control the DOM .
It just like plug and play.

Below URL contains the war file for below example

Now am going to give an example to design web page by apply MVC pattern in ext JS. 
Following example covers
  1.      . MVC pattern in Ext js
  2.        Applying Ajax in combo box
  3.        Displaying Ajax JSON response given by JAVA servlet in Ext js grid panel.

                                                    Before AJAX  Response.

   
After Ajax JSON response Show in grid View

Below URL contains the war file for above example




Wednesday 13 May 2015

"main" javax.mail.AuthenticationFailedException:

Java email sending exception with google account

Exception in thread "main" javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuup
534-5.7.14 IqqkRuDjMmFzeS4jfmU-M1RYjtZoIp1O6J8adnURMIQe6PZgmbT456zZ6zVtEFguXUz8Zl
534-5.7.14 mPMP1hK_73NkWIVs37DecEtdMmFRyg9yBu9VhUgjhkB95CRhvJHgBHDfuX5jPVCZFCNuvm
534-5.7.14 KDphLQyCoQ-QsOcTEGT2dnBOcCR4srrI1IaD-ms5o4fX9kcPH9fx3ghZxpTV5PEUSlWSJC
534-5.7.14 l-q_JybfhW1akjyXPY4ZIZb4E1dE> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 gj5sm20978260pbb.22 - gsmtp

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
at javax.mail.Service.connect(Service.java:271)

at javax.mail.Service.connect(Service.java:91)


Solution.
1.Login in your gmail account
2.https://www.google.com/settings/security/lesssecureapps
3. Turn on it






Wednesday 24 September 2014

In crystal report How to avoid or disable login prompt popup in java

Avoid or disable  CrystalReport login prompt popup in java

use belew code in viewer file:-


CrystalReportViewer crystalReportPageViewer = new CrystalReportViewer();
    
ConnectionInfos connInfos = new ConnectionInfos();
IConnectionInfo connInfo1 = new ConnectionInfo();
    
 connInfo1.setUserName("YourUserName");
        connInfo1.setPassword("Yourpassword");
        connInfos.add(connInfo1);

    crystalReportPageViewer.setEnableParameterPrompt(false);
    crystalReportPageViewer.setDatabaseLogonInfos(connInfos);








Cystal Report new line with java .

By using Can Grow option in conditional formulas, we can achieve the new line in crystal 
report 

if it returns true, can Grow option will enabled for the required field.

Sunday 17 August 2014

Spring Exception

org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491) 


The above exception relates the command object
It will occur following scenario.
 1.when  command  object to view page not properly set into the page.
2.command object name misspelled 
 
 

Saturday 16 August 2014

Spring Login Example.

Spring Login with username and password.

Following example demonstrate the simple login in web page.

I have used annotation for the controller

user name:  bala
password : bala123
spring Login Example war

Page 1  Login page:











Page 2 : Success Page:



Page 3 Failure Page
When user enter Incorrect  Username or password.


Following link contains the war file to execute the login spring application

spring Login Example war