Skip to main content

Posts

Showing posts from 2013

Uploading files on Remote Server using Spring 3.x

$(document).ready(function() { $("#quoteCount").keydown(function(event) { if ( event.keyCode == 46 || event.keyCode == 8 ) { // Allow only backspace and delete // let it happen, don't do anything } else { if (event.keyCode < 48 || event.keyCode > 57 ) { // Ensure that it is a number and stop the keypress event.preventDefault(); } } }); });

Executing executable Jar file from Java Program

Sample code to execute jar file from Java Program. Pre-requisite 1. Need to have executable jar file. 2. Copy the code in your workspace and Run the code. package com.test.reusable.enterprise.service; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.commons.lang.exception.ExceptionUtils; public class ExecuteJarFile { public static void main(String[] args) { try { //Method1 to Execute Jar file From Java Program ProcessBuilder pb = new ProcessBuilder("java", "-jar", "HelloWorld.jar"); // command to execute jar file with fileName.jar pb.redirectErrorStream(true); pb.directory(new File("C:/www/")); // Directory path where your jar file is placed. Process p = pb.start();

Reading and Writing text File in Java

var regex = /^([a-zA-Z0-9])+([\w_\.\-]([a-zA-Z0-9])*[a-zA-Z0-9])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; Simple code to demonstrate to Read and Write text file in Java. package email; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ReadAndWriteFile { public static void main(String[] args) {   try {         String content = "This is the content to write into file";          File writeFile = new File("D:/Sample.txt");    // if file doesnt exists, then create it    if (!writeFile.exists()) {     writeFile.createNewFile();    } /**   * When we pass true as parameter to FilwWriter   * then it appends the content in file instead of overwriting the content   */    //FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);    FileWriter fw = new FileW

JOINs in MySQL

JOIN's is used to query data from two or more than two table based on relationship between certain columns in these tables. Tables in Database are related to each other with some constraints like (Primary Key & Foreign Key) Primary Key :- Column with unique value for each row that is not value matching to each other in the column. Foreign Key :- Two tables are mapped through concept of primary and foreign key, that means primary key of one table is used in other table as foreign key. fig : Primary Key and Foreign Key Example Query to create the above two tables. CREATE TABLE `project_mst` (   `PK_PROJECT_ID` varchar(10) NOT NULL,   `PROJECT_NAME` varchar(100) default NULL,   `PROJECT_DURATION` varchar(50) default NULL,   `FK_MANAGER_ID` varchar(10) default NULL,   PRIMARY KEY  (`PK_PROJECT_ID`) ) CREATE TABLE `manager_mst` (   `PK_MANAGER_ID` varchar(10) NOT NULL,   `MANAGER_NAME` varchar(100) default NULL,   PRIMARY KEY  (`PK_MANAGER_ID`) )

Uploading data on Remote Server in Java

This blog demonstrate how to upload data from file to remote server/database. Follow the steps as shown. 1. Create new Dynamic Web Project. 2. Now create all the packages as show in the image below. 3. Create controller with name ImportContact.java 4. Create pojo with name Contact.java 5. Create database layer code with name ImportContactBroker.java 6. Create connectivity with name DBConnection.java 7. Create db connectivity setting file as connectionSetting.java 8. Create jsp page with importcontact.jsp 9. Create supporting files like Constant.java and CsvReader.java 10. You can download the war file and import in your workspace. 11. MultipartRequest in Servlet and inside jsp helps to upload file on the remote server. 12. Download sample csv file from here . 13. Create Table with name Contact in Database as given in configuration file. 14.Just compile and run the code. ImportContact.java package com.uploadfile.controller; import java.io.BufferedReader; impo

Creating Webservice in Java

What is Web Service? A Web service is a method of communication between two electronic devices over the World Wide Web. A Web service is a software function provided at a network address over the web or the cloud, it is a service that is "always on" as in the concept of utility computing. The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network". It has an interface described in a machine-processable format (specifically Web Services Description Language, known by the acronym WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards. Web services creation process 1. To create webservice you have to Download axis2.1.x 2. Open eclipse-> windows ->preferences as shown in screen print. 3. In preferences-&g