Wednesday, 6 August 2014

How to take backup and restore database through commandprompt

It is a good idea to backup your MySQL data occasionally as a precautionary measure. It is also a good idea to create a backup before making any major changes, in-case something goes wrong and you need to revert to the unmodified version. Database backups can also be used to transfer your database from one server to another if you change web hosts.

Open command prompt.



First go to MySQL bin folder.

Take Backup.
mysqldump -u username -ppassword databasename>databasename.sql

Eg:
mysqldump -u root -ppassword Test>c:\Test.sql

If it displays Access is denied.

Run cmd as Administrator

Start->cmd->Right click Run as Administrator.

                                                                     Restore.
mysql -u username -ppassword databasename<databasename.sql

Eg:
mysql -u root -ppassword Test<"c:\Test.sql"




Tuesday, 5 August 2014

Selecting duplicate IDs in mysql

select column_name,count(*) from table_name group by column_name having count(*)>1;

Example:

select consignment_id,count(*) from trip_sheet_trip group by consignment_id having count(*)>1;

Tuesday, 29 July 2014

Hibernate Named Query with Aggregate function

Code for executing Native SQL Query.

Session session = sessionFactory.getCurrentSession();
 
Query query = session.createSQLQuery(
"SELECT sum(hsd_plt_veh) as hsd_plt_veh,sum(randmCost) as randmCost"+
 "from expenses_profit where monthk=:mon and yeark=:yr");
 .setParameter("mon", 1) 
.setParameter("yr", 2014);
 
Object obj=return query.uniqueResult(); 

When we use Native SQL it returns an object.

************************************************************************************************

If we need column names along with the Object use below code.

Session session = sessionFactory.getCurrentSession();
 
Query query = session.createSQLQuery(
"SELECT sum(hsd_plt_veh) as hsd_plt_veh,sum(randmCost) as randmCost"+
 "from expenses_profit where monthk=:mon and yeark=:yr");
.setParameter("mon", 1) 
.setParameter("yr", 2014); 
Map<String, String> expensesProfits =(Map<String, String>) query.uniqueResult();
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE); 
 
//contains column names and values
List<Map<String,Object>> aliasToValueMapList=query.list(); 
********************************************************************************** 
If we use 
 .addEntity(Cost.class) ;
All checks for all columns in the table in query.
Suppose id is 1st column if we dont mention in query 
It gives following error.
 
ERROR org.hibernate.util.JDBCExceptionReporter - Column 'id' not found. 


 
 
 

Sunday, 27 July 2014

Best open sources java web graph library for drawing graphs on jsp webpage

I have found different API's for graphs in which amCharts uses JavaScript/HTML5 have LIVEEDITOR which supports all browsers so powerfull and have motion-charts which change data at run time by default can export charts as images or PDF files.

JSCharts:

JS Charts is a JavaScript based chart generator that requires little or no coding. With JS Charts drawing charts is a simple and easy task, since you only have to use client-side scripting (i.e. performed by your web browser). No additional plugins or server modules are required. Just include our scripts, prepare your chart data in XML, JSON or JavaScript Array and your chart is ready!



http://www.jscharts.com/free-download

JQPlot :

JqPlot is a plotting and charting plugin for the jQuery Javascript framework. jqPlot produces beautiful line, bar and pie charts with many features:
  • Numerous chart style options.
  • Date axes with customizable formatting.
  • Up to 9 Y axes.
  • Rotated axis text.
  • Automatic trend line computation.
  • Tooltips and data point highlighting.
  • Sensible defaults for ease of use.

   http://www.jqplot.com/

amCharts:

We offer JavaScript/HTML5 charts for most of your needs. The set includes serial (column, bar, line, area, step line, step without risers, smoothed line, candlestick and ohlc graphs), pie/donut, radar/polar, y/scatter/bubble, Funnel/Pyramid charts and Angular Gauges. Our charts offer unmatched functionality and performance in a modern, standards compliant package. Our JS charting library is responsive and supported by touch/mobile devices.


http://www.amcharts.com/javascript-charts/.


Tuesday, 15 July 2014

Silent print of PDF using JAVA.

I have used javax.print API to perform printing of PDF without user interaction.
It is running only in MAC still search is going on for Windows.

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.event.PrintJobAdapter;
import javax.print.event.PrintJobEvent;


public class Abc {
  /**
  * @param args
  */
  public static void main(String[] args) {

    new Abc().print();
  }
  public void print() {
  /*
    The format of Page will be PDF.
    We have different types based on what we pass to printer.
  */
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;

   // Number of printers in network will be recognized.

    PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
    FileInputStream psStream = null;  
    try {  
        psStream = new FileInputStream
       ("E:/apache-tomcat-7.0.30/webapps/pdf/TripSheetReport 27-3.pdf");  
        } catch (FileNotFoundException ffne) {  
             ffne.printStackTrace();  
        }  
    if (psStream == null) {  
        return;  
    }       
    if (services.length > 0)
    {
       PrintService myService = null;
       for(PrintService service : services) {
       System.out.println(service.getName());
       // Check whether connected printer is recognized.
          if(service.getName().contains("M1136")) {
            myService = service;
     break;
          }
       }
       DocPrintJob printJob = myService.createPrintJob();
       Doc document = new SimpleDoc(psStream, flavor, null);
       
       try {
 
         // Sends the document to print.
  printJob.print(document, new HashPrintRequestAttributeSet());
     } catch (PrintException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
      }
 }
  else
  {
     System.out.println("No PDF printer available.");
  }       
 }
        // To check the status of Print.

   class PrintJobWatcher {
      boolean done = false;
      PrintJobWatcher(DocPrintJob job) {
         job.addPrintJobListener(new PrintJobAdapter() {
       public void printJobCanceled(PrintJobEvent pje) {
          allDone();
       }
       public void printJobCompleted(PrintJobEvent pje) {
         allDone();
       }
       public void printJobFailed(PrintJobEvent pje) {
         allDone();
       }
       public void printJobNoMoreEvents(PrintJobEvent pje) {
         allDone();
       }
       void allDone() {
         synchronized (PrintJobWatcher.this) {
           done = true;
           System.out.println("Printing done ...");
           PrintJobWatcher.this.notify();
         }
       }
   });
 }
   
}
}

Friday, 21 March 2014

The official language running the site used by 1.2 billion users(Facebook).

Facebook unveils Hack, a faster programming language to power the social network.

At Facebook, the codebase that runs the social networking site is written in Hack.
The Menlo Park, Calif.-based social networking titan said it had streamlined PHP, made it better, and that Hack was now the official language running the site used by 1.2 billion users.

Facebook engineers embellished the code internally and announced the upgrade , according to a post.
Facebook did not post the update to its site, but the beta version is now live and can be seen.

Company engineers said inherent challenges in the PHP code sometimes made simple tasks “tricky or cumbersome” and that coding errors were sometimes not detected until the script had gone live.

Hack has changed that, Facebook said.  Thus, the company said, “Hack was born.”
Facebook explained that one of the major embellishments to PHP thus:
“Our principal addition is static typing. We have developed a system to annotate function signatures and class members with type information; our type checking algorithm (the type checker) infers the rest. Type checking is incremental, such that even in the same file, some code can be converted to Hack while the rest remains PHP.

Technically speaking, Hack is a gradually typed language: dynamically typed code interoperates seamlessly with statically typed code.

“The Hack adds additional features beyond static type checking, including collections, lambda expressions, and run time enforcement of return and additional parameter types….We are delighted to open-source both Hack and the tools that we used to convert our codebase (http://hacklang.org).”
Facebook is hosting a Hack-related event at its campus next month.

 

Wednesday, 12 March 2014

Umoove Experience:The 3D Face & Eye Tracking Flying Game

Super Precise Eye-Tracking Software

 Eye-tracking could be the next big thing when it comes to motion-sensing technology, and it seems that Israeli startup Umoove is on its way to incorporating it in lots of future tech.

Umoove - which has raised around $3 million in total funding, according to CrunchBase - burst onto the scene in a big way with an iOS game called Umoove Experience that demos its super precise face-tracking technology.
The game uses your phone's front-facing camera to track your head movements as you fly around and gather potions. It's fun, but more importantly, it's accurate. And that's where Umoove's next bit of technology comes in.

The company will unveil new eye-tracking technology in the next few months that uses the existing camera in your phone or tablet.
"Eye tracking is mainly about understanding the user without him even actively interacting," 

" It is for real analytics that understand users' interests, medical diagnoses based on following your eye movement, advertising that knows if you looked at it, content that changes based on its understanding of your interests, or just a whole new world of human computer interaction in which you don't have to tell the computer everything, it just understands you like a close friend does." said by
Umoove's CEO Yitzi Kempinski.

 

Thursday, 20 February 2014

java.net.BindException:Address already in use:JVM_Bind ( Tomcat startup problem )

This exception is self explanatory, its saying that a Java application is trying to connect on port but that port is already used by some other process and JVM Bind to that particular port, is failed. Now to fix this error you need to find out which process is listening of port your connecting, we will how to find a process which is listening on a particular port

Find process which is listening on port 8080 in Windows netstat command.

C:\>netstat -ano | find "8080"


Now kill the process

 
Now Process killed successfully.



 

Tuesday, 11 February 2014

Budget Nokia Android phone headed for MWC

Nokia will reveal its much rumoured Android smartphone at this year’s Mobile World Congress event in Barcelona at the end of February, according to a new report.

The so-called Nokia X, which is powered by Google’s Android OS rather than Windows Phone, began development before Microsoft struck a deal to purchase Nokia last September.

Despite that deal being signed and sealed, however, Nokia still plans to release its Android experiment. If The Wall Street Journal is to be believed, the Nokia X will be officially unveiled at MWC 2014 from February 24.

It’s believed that Nokia is targeting emerging markets with its modestly specced Android phone. The lack of restrictions surrounding the Android OS has enabled the company to create the kind of stripped-back smartphone they could never achieve with Microsoft’s strict Windows Phone hardware guidelines.

Rumour suggests that the Nokia X will be a low-end smartphone at an extremely affordable price. It will run on a modest 1.2GHz dual-core CPU backed by just 512MB of RAM and 4GB of (expandable) internal storage, and will sport a 3-megapixel camera.

A 4-inch 800 x 480 display is also rumoured, which is extremely conservative for an Android phone. Speaking of Android, the Nokia X will apparently run on Android 4.1 Jelly Bean, which is quite a bit behind the curve. The most recent version available is Android 4.4 KitKat.

Despite running on Google’s OS, the new Nokia phone reportedly won’t be able to access key Android features such as the Google Play Store, which its the platform’s main source of apps. Nor will it feature Google Maps, with Nokia’s own Here Maps taking its place.

It seems Nokia is using the bare bones of Android to create a highly customised UI, which we’ve seen before in the likes of the Amazon Kindle Fire range.

Nokia will reveal its much rumoured Android smartphone at this year’s Mobile World Congress event in Barcelona at the end of February, according to a new report.

The so-called Nokia X, which is powered by Google’s Android OS rather than Windows Phone, began development before Microsoft struck a deal to purchase Nokia last September.

Despite that deal being signed and sealed, however, Nokia still plans to release its Android experiment. If The Wall Street Journal is to be believed, the Nokia X will be officially unveiled at MWC 2014 from February 24.

It’s believed that Nokia is targeting emerging markets with its modestly specced Android phone. The lack of restrictions surrounding the Android OS has enabled the company to create the kind of stripped-back smartphone they could never achieve with Microsoft’s strict Windows Phone hardware guidelines.

Rumour suggests that the Nokia X will be a low-end smartphone at an extremely affordable price. It will run on a modest 1.2GHz dual-core CPU backed by just 512MB of RAM and 4GB of (expandable) internal storage, and will sport a 3-megapixel camera.

A 4-inch 800 x 480 display is also rumoured, which is extremely conservative for an Android phone. Speaking of Android, the Nokia X will apparently run on Android 4.1 Jelly Bean, which is quite a bit behind the curve. The most recent version available is Android 4.4 KitKat.

Despite running on Google’s OS, the new Nokia phone reportedly won’t be able to access key Android features such as the Google Play Store, which its the platform’s main source of apps. Nor will it feature Google Maps, with Nokia’s own Here Maps taking its place.

It seems Nokia is using the bare bones of Android to create a highly customised UI, which we’ve seen before in the likes of the Amazon Kindle Fire range.
Read more at http://www.trustedreviews.com/news/nokia-android-phone-headed-for-mwc#iGfgpgGwv7CF3yel.99
Nokia will reveal its much rumoured Android smartphone at this year’s Mobile World Congress event in Barcelona at the end of February, according to a new report.

The so-called Nokia X, which is powered by Google’s Android OS rather than Windows Phone, began development before Microsoft struck a deal to purchase Nokia last September.

Despite that deal being signed and sealed, however, Nokia still plans to release its Android experiment. If The Wall Street Journal is to be believed, the Nokia X will be officially unveiled at MWC 2014 from February 24.

It’s believed that Nokia is targeting emerging markets with its modestly specced Android phone. The lack of restrictions surrounding the Android OS has enabled the company to create the kind of stripped-back smartphone they could never achieve with Microsoft’s strict Windows Phone hardware guidelines.

Rumour suggests that the Nokia X will be a low-end smartphone at an extremely affordable price. It will run on a modest 1.2GHz dual-core CPU backed by just 512MB of RAM and 4GB of (expandable) internal storage, and will sport a 3-megapixel camera.

A 4-inch 800 x 480 display is also rumoured, which is extremely conservative for an Android phone. Speaking of Android, the Nokia X will apparently run on Android 4.1 Jelly Bean, which is quite a bit behind the curve. The most recent version available is Android 4.4 KitKat.

Despite running on Google’s OS, the new Nokia phone reportedly won’t be able to access key Android features such as the Google Play Store, which its the platform’s main source of apps. Nor will it feature Google Maps, with Nokia’s own Here Maps taking its place.

It seems Nokia is using the bare bones of Android to create a highly customised UI, which we’ve seen before in the likes of the Amazon Kindle Fire range.
Read more at http://www.trustedreviews.com/news/nokia-android-phone-headed-for-mwc#iGfgpgGwv7CF3yel.99

Samsung galaxy y GT-S6102 No Notifications of USB Connected but charging



First try this:

http://blog.vacs.fr/?post/2010/12/24/How-to-repair-the-USB-not-detected-problem-on-Android-Samsung-phones

 If above link is not working out then perform following actions:

1. Restart your mobile by holding three buttons... Volume up+home button+power button.. Now when you see Samsung logo release the buttons... After few seconds you will see 4 options written in red text.. Which is stock recovery (Android system recovery)... select first option there.. ("reboot system now").. It will say "Rebooting..." in green colour..

2. Now when screen gets black.. immediately press and hold volume down+home button+power button..
you will see a page saying "Warning"
A custom OS can cause critical problems in your phone and installed applications.. and it will say some more in next paragraph..
Dont worry about it.. Now press "Volume up" to continue to odin mode..

3.you will see ODIN MODE written on top of screen in red..
Now make sure you are connected to your pc through usb cable and pc is logged in and open odin file..

4. In Odin you will see a yellow color in one box below "ID:COM" section.. If you are not seeing yellow restart your mobile and do same process from step 2. also restart your pc if its still not showing yellow. If it is showing then good.

5. Now select "PDA" button under "Files [Download]" section.. select "PDA_S6102_(your firmware version no.).tar.md5" file
Now select "PHONE" button below "PDA" button in "Files [Download]" section.. select "MODEM_S6102_(your firmware version no.).tar.md5" file
Now select "CSC" button below "PHONE" button in "Files [Download]" section.. select "CSC_S6102_(your firmware version no.).tar.md5" file

6. Now remember!! Only "Auto Reboot" "F. Reset Time" options should be selected..
PDA
PHONE
MODEM also should be selected..

7. Now you are ready to flash through odin.. Just press "Start" button.. and wait around 10 minutes until odin finishes and the "yellow" box should show green... It will usually finish within 52 seconds to be precise..

8. Now your phone will reboot. If it starts showing Samsung logo again after few minutes.. Restart your mobile by holding three buttons... Volume up+home button+power button.. Now when you see Samsung logo release the buttons... After few seconds you will see 4 options written in red text.. Which is stock recovery (Android system recovery)...and select "wipe data/factory" and select first option there.. ("reboot system now").. It will say "Rebooting..." in green colour..

9. Now enjoy your brand new stock rom.. Hope this helps you!!

Tuesday, 4 February 2014

Web Architectures

Web App Architectures: 1- tier,2-tier,3-tier,n-tier.

1-tier Architecture:

All 3 layers are on same machine 
Presentation,Business Logic,Database are tightly connected.
Scalability: Single processor means hard to increase the volume of processing speed.
Portability:  Moving to new machine may mean rewriting every thing.
Maintenance: Changing one layer requires to change  in other layers.

2-tier Architecture:

The Two-tier architecture is divided into two parts:
1) Client Application (Client Tier)
2) Database (Data Tier)

The two-tier is based on Client Server architecture. The two-tier architecture is like client server application. The direct communication takes place between client and server. There is no intermediate between client and server. Because of tight coupling a 2 tiered application will run faster
  • Database runs on Server 
  • Separated from client
  • Easy to switch to different databases
  • Presentation and logic layers still tightly connected
Advantages:
  1. Easy to maintain and modification is bit easy
  2. Communication is faster
Disadvantages:
  1. In two tier architecture application performance will be degrade upon increasing the users.
  2. Cost-ineffective 
 3-tier Architecture:
Three-tier architecture typically comprise a presentation tier, a business or data access tier, and a data tier. Three layers in the three tier architecture are as follows:
1) Client layer
2) Business layer
3) Data layer

1) Client layer:
It is also called as Presentation layer which contains UI part of our application. This layer is used for the design purpose where data is presented to the user or input is taken from the user. For example designing registration form which contains text box, label, button etc.
2) Business layer:
In this layer all business logic written like validation of data, calculations, data insertion etc. This acts as a interface between Client layer and Data Access Layer. This layer is also called the intermediary layer helps to make communication faster between client and data layer.
3) Data layer:
In this layer actual database is comes in the picture. Data Access Layer contains methods to connect with database and to perform insert, update, delete, get data from database based on our input data.
  • Each layer can potentially run on a different machine.
  • Presentation,Logic,Data Layers disconnected. 
Advantages
  1. High performance, lightweight persistent objects
  2. Scalability – Each tier can scale horizontally
  3. Performance – Because the Presentation tier can cache requests, network utilization is minimized, and the load is reduced on the Application and Data tiers.
  4. High degree of flexibility in deployment platform and configuration
  5. Better Re-use
  6. Improve Data Integrity
  7. Improved Security – Client is not direct access to database.
  8. Easy to maintain and modification is bit easy, won’t affect other modules
  9. In three tier architecture application performance is good.
Disadvantages
  1. Increase Complexity/Effort
 

Monday, 20 January 2014

Delete duplicate numbers from the file




Program:


import java.io.*;
class FileWriterDemo1 
{
  public static void main(String[] args)throws IOException
  {
    BufferedReader br1=
     new BufferedReader(new FileReader("input.txt"));
    PrintWriter out=new PrintWriter("output.txt");
    String target=br1.readLine();
    while(target!=null)
    {
 boolean available=false;
 BufferedReader br2=
          new BufferedReader(new FileReader("output.txt"));
 String line=br2.readLine();
 while(line!=null)
 {
          if(target.equals(line))
   {
     available=true;
     break;
   }
     line=br2.readLine();
 }
 if(available==false)
 {
   out.println(target);
   out.flush();
 }
 target=br1.readLine();
     }
}
}