Recommented
opentaps
opentaps Open Source ERP CRM ecommerce Warehouse Inventory Financials Accounting Purchasing Supply Chain Management Business Intelligence
www.opentaps.org/
Download opentaps
Content about Java ERP Solution for Reviews Best ERP Software for sale and Free Software with Java OpenSource for Free Download
SQL queries create table example sql command to create table
Labels:
MySQL,
SQL Command
We can Create table with SQL command for example code below
CREATE TABLE table_name(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size));
Example SQL code for create table
CREATE TABLE Student(
student_id int,
student_name varchar(255));
Note: with
difference DBMS the command will not the same for example mysql have
datatype varchar but in Oracle use data type Vaarchar2
Mysql query for creating table example sql code for create new table with select command
Labels:
MySQL,
SQL Command
We can create table with select command from another table with example sql command below
Example sql command for mysql query for creating table
CREATE TABLE new_std_table
SELECT * from std_table
SELECT * from std_table
you can select with specify field name or using where condition , group by , order by for example below
CREATE TABLE new_std_table
SELECT std_id,std_name from std_table where std_name like '%anna%' order by std_id
SELECT std_id,std_name from std_table where std_name like '%anna%' order by std_id
Note: this command will support MySql DBMS in other DBMS may be some difference
Mysql create table int with unsigned int column example sql command
Labels:
MySQL,
SQL Command
Mysql create table int with unsigned int column example sql command to caeate table with
mysql create unsigned int column and mysql create table unsigned int primary key in below
mysql create unsigned int column and mysql create table unsigned int primary key in below
Mysql create unsigned int column
using key word UNSIGNED after datatype of field for example
CREATE TABLE test_table (
test_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
test_desc TEXT
);
Mysql create table unsigned int primary key
CREATE TABLE test_table (
test_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
test_desc TEXT
PRIMARY KEY ('test_id')
);
Note: using keyword
UNSIGNED to tell the data type is UNSIGNED and using keyword PRIMARY KEY (fieldname) to tell this field is primary keySpring Framework with Interceptor
Labels:
Developer Web Java,
JSP,
Spring framework,
Spring Interceptor
Example for using Spring Framework Interceptor for do something before go to Controller
Interceptor Class
package com.en.interceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.en.model.MasterModel;
public class MasterInterceptor extends HandlerInterceptorAdapter{
private String errorURL;
private MasterModel model;
public String getErrorURL() {
return errorURL;
}
public void setErrorURL(String errorURL) {
this.errorURL = errorURL;
}
public MasterModel getModel() {
return model;
}
public void setModel(MasterModel model) {
this.model = model;
}
}
package com.en.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
public class ExampleInterceptor extends MasterInterceptor{
private static Logger logger = Logger.getLogger(ExampleInterceptor.class);
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//request.getRequestDispatcher(errorURL).forward(request, response);
//return false;
logger.info("Interceptor running");
return true;
}
}
Spring Configuration is the same for Spring Bean config
Config to URL Mapping that need to use interseptor
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref local="exampleInterceptor"/>
</list>
</property>
<property name="mappings">
<props>
<prop key="/example_insert.html">exampleController</prop>
<prop key="/example_load.html">exampleController</prop>
<prop key="/example_delete.html">exampleController</prop>
<prop key="/example_ws.html">exampleController</prop>
<prop key="/example_sap.html">exampleController</prop>
</props>
</property>
</bean>
Spring Framework How to use multiaction controller with binding method name
Labels:
Developer Web Java,
J2EE,
JSP,
Spring framework
You can use mvc class : org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver
to bind url to method in MVC Class for example in below
to bind url to method in MVC Class for example in below
CONTROLLER DEFINITIONS
<bean id="welcomeController" class="com.spring.controller.WelcomeController">
<property name="methodNameResolver" ref="welcomeControllerResolver"/>
</bean>
<bean id="welcomeControllerResolver"
class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/welcome1.cdr">loadWelcome1</prop>
<prop key="/welcome2.cdr">loadWelcome2</prop>
</props>
</property>
</bean>
** loadWelcome1 and loadWelcome2 is method name in Controller class WelcomeController
URL MAPPING
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome1.cdr">welcomeController</prop>
<prop key="/welcome2.cdr">welcomeController</prop>
</props>
</property>
</bean>
each url can binding to the same controller it's will be defind method mapping in ControllerResolver
PHP Remove HTML Tag Cleaning Text
Labels:
Developer PHP
We can parse HTML page to collect only normal text with PHP function strip_tags()
for example to using this functoin in bilow
for example to using this functoin in bilow
Example to using PHP strip_tags()
$html_page="<a href='test.php'>This is my page </a>";
$txt.=strip_tags($html_page);
The output is return
This is my page 
Note** If we have complex HTML page the output is not perfect we need to clean it self for example
$description.=" ".strip_tags(trim($html_page))." ".$main_term;
$description = ereg_replace( "\n", " ", $description);
$description = ereg_replace( "\r", " ", $description);
$description = ereg_replace( " ", " ", $description);
$description = ereg_replace( " ", " ", $description);
$description = ereg_replace( " ", " ", $description);
$description = ereg_replace( " ", " ", $description);
PHP mysql tutorial example to manage mysql database with PHP
Labels:
Developer PHP
Mysql is the most popular free DBMS with high performance we can use PHP to manage MySQL with query , insert , delete , update
This tutorial is basis for using PHP to execute SQL command pass to MySQL DBMS
This tutorial is basis for using PHP to execute SQL command pass to MySQL DBMS
PHP MySQL tutorial
//Connect database
$username="root";
$password="root";
$database="testdb";
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//SQL Query command
$query="select * from my_table where p_type='Y' order by last_view desc limit 0,10";
$result=mysql_query($query);
$x_num=mysql_numrows($result);
$x_i=0;
while ($x_i < $x_num) {
$code=mysql_result($result,$x_i,"code_id");
$title=mysql_result($result,$x_i,"title");
echo "<BR>".$code." : ".$title;
}
//SQL Insert / Update Command by using only mysql_query();
$query = "insert into test_comment (flash_id,content,post_by,create_date,last_update,ip) ";
$query.="values('$flash_id','$content2','$post_by','$_date','$_date','$ip')";
mysql_query($query);
$query = "update test_table set stat=$new_stat,last_view='$last_view' where code_id=$code_id";
mysql_query($query);
Tip : you can using command mysql_query(); to execute SQL command to mysql it's very easy
PHP Mysql tutorial for beginners with examples code and tip
Labels:
Developer PHP
PHP Mysql tutorial for beginners with examples code and tip for query with select commans ,
insert delete update with mysql_query();
Example PHP Mysql for Connect Database (PHP Mysql tutorial for beginners)
insert delete update with mysql_query();
Example PHP Mysql for Connect Database (PHP Mysql tutorial for beginners)
you can use function mysql_connect(); to connect to mysql dbms by send db host , db user , db password
and use function mysql_select_db(); to connect to databalse by send database name for example
and use function mysql_select_db(); to connect to databalse by send database name for example
$username="dbuser";
$password="dbpassword";
$database="mydatabase";
mysql_connect("localhost",$username,$password);
//select database if fail print error
@mysql_select_db($database) or die( "Unable to select database");
Example PHP Mysql for Query with SQL command (PHP Mysql tutorial for beginners)
you can execute any SQL command by sending parameter to functoin mysql_query();
for example in query it's will return data in mysql_result();
for example in query it's will return data in mysql_result();
$query="select * from test_comment where flash_id='$code_id' order by comment_id desc";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;while ($i < $num) {
$content =mysql_result($result,$i,"content");
echo "
".$content;
}
Example PHP Mysql for Insert with SQL command (PHP Mysql tutorial for beginners)
for Insert mode it's easy way to using function mysql_query(); to execute SQL command with insert statement example code in below
$query = "insert into test_comment (flash_id,content,post_by,create_date,last_update,ip) ";
$query.="values('$flash_id','$content2','$post_by','$_date','$_date','$ip')";
mysql_query($query);
Example PHP Mysql for Delete with SQL command (PHP Mysql tutorial for beginners)
for delete mode it's the same way by using mysql_query(); example code in below\
$query = "delete from test_comment ";
mysql_query($query);
Example PHP Mysql for Update with SQL command (PHP Mysql tutorial for beginners)
for update mode it's the same 
$query = "update test_comment set title='test' where code_id='1001'";
mysql_query($query);
Tip : With PHP and MySQL you can only using mysql_query(); you can send any SQL command to execute 
Eclipse to uppercase how to switch text between Upper case and Lover case
We can change text from Lower case to upper Case or upper Case to Lower Case by using eclipse shortcut for example in below
Eclipae shortcut by default for Upper case or Lower case
Lower case: CTRL+SHIFT+Y
Upper case: CTRL+SHIFT+X
Eclipae shortcut by default for Upper case or Lower case
Lower case: CTRL+SHIFT+Y
Upper case: CTRL+SHIFT+X
Big Data Tools for quick startup
Apache Hadoop
Apache Hive
Apache HBase
Apache Pig
Apache Storm
Apache Solr
Apache Falcon
Apache Sqoop
Apache Flume
Apache Oozie
Apache Ambari
Apache Mahout
Apache ZooKeeper
Apache Knox
Oracle Index and tip for using HINT
We can using Index to tunup performance in database
and for more performance in Oracle we can use HINT for select index when query witch example below
and for more performance in Oracle we can use HINT for select index when query witch example below
Example to create index
field_a create index name indx_a
field_b create index name indx_b
field_a create index name indx_a
field_b create index name indx_b
When Query data
select * from my_table where field_a='xxx';
select * from my_table where field_b='xxx';
The result is good time response ... very fast
select * from my_table where field_a='xxx';
select * from my_table where field_b='xxx';
The result is good time response ... very fast
But when using this query
select * from my_table where field_a='xxx' and field_b='yyy';
Can see it's response is not good ... slowly
Can see it's response is not good ... slowly
I was very confused that why it's not good when we were both of index field in ?
How ever i try to tune up index whtch below it's ok good response and very fast
create index indx_ab on my_table (field_a,field_b)
How ever i try to tune up index whtch below it's ok good response and very fast
create index indx_ab on my_table (field_a,field_b)
I try to research and fron the HINT we can using HINT to select INdex for example below
select /*+INDEX(mt,indx_a)*/ * from my_table mt where field_a='xxx' and field_b='yyy';
It's to fast when query witch no need to create additional index .
JSP set content type ms word to export HTML to ms word doc
JSP set content type ms word to export HTML to ms word doc
Using response.addHeader() to config header attribute with example response.addHeader("Content-disposition","attachment; filename=attes.doc");
response.addHeader("Content-Type","application/vnd.ms-word; charset=utf-8");
Java Date Format with SimpleDateFormat
Labels:
Developer Basic Java
Java Date Format with SimpleDateFormat
You can use java.text.SimpleDateFormat to farmat Date
For example in below
For example in below
Date date=new Date();
System.out.println("No format :"+date);
java.text.SimpleDateFormat df= new java.text.SimpleDateFormat();
System.out.println("No pattern format :"+df.format(date));
df.applyPattern("dd/mm/yyyy");
System.out.println("dd/mm/yyyy format :"+df.format(date));
df.applyPattern("dd/mm/yyyy HH:mm:ss");
System.out.println("dd/mm/yyyy HH:mm:ss format :"+df.format(date));
Out put when run this code
No format :Thu Apr 05 16:29:18 ICT 2012
No pattern format :5/4/2555, 16:29 ?.
dd/mm/yyyy format :05/29/2555
dd/mm/yyyy HH:mm:ss format :05/29/2555 16:29:18
No pattern format :5/4/2555, 16:29 ?.
dd/mm/yyyy format :05/29/2555
dd/mm/yyyy HH:mm:ss format :05/29/2555 16:29:18
Java ArrayList Example how to use Array List for add content and loop result
Labels:
Developer Basic Java
Exapmple code for using java.utill.ArrayList
package example.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;
public class ArrayListExample {
public void arrayListExample(){
//Create ArrayList Object
ArrayList arrayList=new ArrayList();
//Store data to ArrayList
arrayList.add("value1");
arrayList.add("value2");
arrayList.add("value3");
arrayList.add("value4");
arrayList.add("value5");
//Test Print all data with toString()
System.out.println("ArrayList Data befor "+arrayList);
//Remove data from ArrayList
String removeValue=arrayList.remove(2);
boolean remove1=arrayList.remove("value1");
boolean remove2=arrayList.remove("value3");
Vector v=new Vector();
v.add("value2");
boolean remove3=arrayList.removeAll(v);
//Removed data can return in VAL
System.out.println("Remove Value "+removeValue);
System.out.println("Remove1 "+remove1);
System.out.println("Remove2 "+remove2);
System.out.println("Remove3 "+remove3);
System.out.println("ArrayList Data after "+arrayList);
//Ged data from ArrayList
System.out.println("-- Example for Get Value from ArrayList --");
System.out.println("Get ArrayList value: "+arrayList.get(0));
System.out.println("Contains ArrayList: "+arrayList.contains("value1"));
System.out.println("Contains ArrayList: "+arrayList.contains("value3"));
//Loop data from Array List
System.out.println("-- Example for Iterate list from ArrayList --");
Iterator it=arrayList.iterator();
while(it.hasNext()){
String value=it.next();
System.out.println("List Iterated Value: "+value);
}
System.out.println("-- Example for Loop from ArrayList --");
for (String temp:arrayList){
System.out.println("For value ArrayList "+temp);
}
}
public static void main (String args[]){
//Test the code in main method
ArrayListExample arryList=new ArrayListExample();
arryList.arrayListExample();
}
}
Test Result in below
ArrayList Data befor [value1, value2, value3, value4, value5]
Remove Value value3
Remove1 true
Remove2 false
Remove3 true
ArrayList Data after [value4, value5]
-- Example for Get Value from ArrayList --
Get ArrayList value: value4
Contains ArrayList: false
Contains ArrayList: false
-- Example for Iterate list from ArrayList --
List Iterated Value: value4
List Iterated Value: value5
-- Example for Loop from ArrayList --
For value ArrayList value4
For value ArrayList value5
Java HashSet Example Code for add and collect data from HashSet
Labels:
Developer Basic Java
Example Code for using java.util.HashSet
HashSet is a Class in package java.util we can store data and collect data from HashSet like Array
//Create Instance for HashSet of String
HashSet hashSet=new HashSet();
//Add data to HashSet ...the same way for list
hashSet.add("aa");
hashSet.add("bb");
hashSet.add("ab");
//Check contain data in HashSet
System.out.println("HashSet contails "+hashSet.contains("aa"));
System.out.println("HashSet contails "+hashSet.contains("cc"));
//Loop data in hash Set
Iterator it=hashSet.iterator();
while(it.hasNext()){
System.out.println("HashSet Next Data "+it.next());
}
Result when run program
HashSet contails true
HashSet contails false
HashSet Next Data aa
HashSet Next Data ab
HashSet Next Data bb
Java TreeSet Example to sorting data with java TreeSet
Labels:
Developer Basic Java
Java TreeSet is a Class int package java.util
We can use TreeSet to auto sorting data in the Tree for example in below
We can use TreeSet to auto sorting data in the Tree for example in below
Example to using java.util.TreeSet
//Create instance for TreeSet of String
TreeSet treeSet=new TreeSet();
//Store data to TreeSet with mix order
treeSet.add("aa1");
treeSet.add("aa2");
treeSet.add("aa3");
treeSet.add("bb1");
treeSet.add("bb2");
//Test containing data .. the same function for Other Collection
System.out.println("TreeSet contails "+treeSet.contains("aa1"));
System.out.println("TreeSet contails "+treeSet.contains("bb1"));
//Loop data from TreeSet
Iterator it=treeSet.iterator();
while(it.hasNext()){
System.out.println("TreeSet Next Data "+it.next());
}
Result when run program
TreeSet contails true
TreeSet contails true
TreeSet Next Data aa1
TreeSet Next Data aa2
TreeSet Next Data aa3
TreeSet Next Data bb1
TreeSet Next Data bb2
TreeSet contails true
TreeSet Next Data aa1
TreeSet Next Data aa2
TreeSet Next Data aa3
TreeSet Next Data bb1
TreeSet Next Data bb2
Amazed !! data will sorting automatic 
Java StringBuffer Example to append a lot of String with StringBuffer
Labels:
Developer Basic Java
When we need to append String with java String we can using a simple Code in below
String x="test1";
x=x+"test2" ;
x=x+"test2" ;
With this code have some problem when we adding a lot of String it's not support !! 
We have the best solution to append String by using StringBuffer we can append a lot of data
We have the best solution to append String by using StringBuffer we can append a lot of data
StringBuffer is a Class in paclage java.lang
Example Code for using StringBuffer
//Create instance for StringBuffer
StringBuffer stringbuffer =new StringBuffer();
//Append String to StringBuffer
stringbuffer.append("str1");
stringbuffer.append("str2");
stringbuffer.append("str3");
/*
..
.. You can append a lot of data you want
..
*/
//Transform it to String
String data=stringbuffer.toString();
System.out.println("StringBuffer data :"+data);
Out put when Run Program
StringBuffer data :str1str2str3
Java Hashmap Example example code to using Hashmap in Java
Labels:
Developer Basic Java
HashMap is a Collection Class in package java.util
HashMap store data with key and value for example in below
HashMap store data with key and value for example in below
Example to using HashMap in Java
package example.util;
import java.util.*;
public class HashmapExample {
public void hashmapExample(){
//Create HashMap Object
HashMap<String,String> hashmap=new HashMap<String,String>();
//Store and Remove data from HashMap
hashmap.put("key1", "value1");
hashmap.put("key2", "value2");
hashmap.put("key3", "value3");
String key3=hashmap.remove("key3");
//Get Value from HashMap by using Key
System.out.println("-- Example for Get Value from HashMap --");
System.out.println("Get Hashmap value: "+hashmap.get("key1"));
System.out.println("Remove Hashmap value: "+key3);
System.out.println("Contains Key Hashmap: "+hashmap.containsKey("key1"));
System.out.println("Contains Key Hashmap: "+hashmap.containsKey("key3"));
System.out.println("Contains Value Hashmap: "+hashmap.containsValue("value1"));
System.out.println("Contains Value Hashmap: "+hashmap.containsValue("value3"));
//Loop data from HashMap by keySet and using key to get the Value
System.out.println("-- Example for Iterate list from Hash Map --");
Iterator<String> it=hashmap.keySet().iterator();
while(it.hasNext()){
String key=it.next();
String value=hashmap.get(key);
System.out.println("By Key :Key : "+key+" Value: "+value);
}
//Loop data from HashMap by Value List all value no need to using Key
it=hashmap.values().iterator();
while(it.hasNext()){
System.out.println("Value "+it.next());
}
}
public static void main (String args[]){
//Test run program in main method
HashmapExample hashmap=new HashmapExample();
hashmap.hashmapExample();
}
}
Output when Run Test Program
-- Example for Get Value from HashMap --
Get Hashmap value: value1
Remove Hashmap value: value3
Contains Key Hashmap: true
Contains Key Hashmap: false
Contains Value Hashmap: true
Contains Value Hashmap: false
-- Example for Iterate list from Hash Map --
By Key :Key : key2 Value: value2
By Key :Key : key1 Value: value1
Value value2
Value value1
Get Hashmap value: value1
Remove Hashmap value: value3
Contains Key Hashmap: true
Contains Key Hashmap: false
Contains Value Hashmap: true
Contains Value Hashmap: false
-- Example for Iterate list from Hash Map --
By Key :Key : key2 Value: value2
By Key :Key : key1 Value: value1
Value value2
Value value1
Java Hashtable Example Code for using Hashtable store data and get data
Labels:
Developer Basic Java
You can use Hasetable to atore data with key and value for example
key1= data1
key2= data 2
key3= data 3
key1= data1
key2= data 2
key3= data 3
you can use key collect data from Hashtable however you can collect list of key or value with keySet and valuesSet
Example Code to using java Hashtable
** you need to inport java.util package
** you need to inport java.util package
package example.util;
import java.util.*;
public class HashtableExample {
public void hashtableExample(){
//Create Hashtable Object
Hashtable<String,String> hashtable=new Hashtable<String,String>();
//Store and Remove data from Hashtable
hashtable.put("key1", "value1");
hashtable.put("key2", "value2");
hashtable.put("key3", "value3");
String key3=hashtable.remove("key3");
System.out.println("-- Example for Get Value from Hashtable --");
System.out.println("Get Hashtable value: "+hashtable.get("key1"));
System.out.println("Remove Hashtable value: "+key3);
System.out.println("Contains Key Hashtable: "+hashtable.containsKey("key1"));
System.out.println("Contains Key Hashtable: "+hashtable.containsKey("key3"));
System.out.println("Contains Value Hashtable: "+hashtable.containsValue("value1"));
System.out.println("Contains Value Hashtable: "+hashtable.containsValue("value3"));
System.out.println("-- Example for Iterate list from Hashtable --");
Iterator<String> it=hashtable.keySet().iterator();
while(it.hasNext()){
String key=it.next();
String value=hashtable.get(key);
System.out.println("By Key :Key : "+key+" Value: "+value);
}
it=hashtable.values().iterator();
while(it.hasNext()){
System.out.println("Value "+it.next());
}
}
public static void main (String args[]){
HashtableExample hashtable=new HashtableExample();
hashtable.hashtableExample();
}
}
Result when run test
-- Example for Get Value from Hashtable --
Get Hashtable value: value1
Remove Hashtable value: value3
Contains Key Hashtable: true
Contains Key Hashtable: false
Contains Value Hashtable: true
Contains Value Hashtable: false
-- Example for Iterate list from Hashtable --
By Key :Key : key2 Value: value2
By Key :Key : key1 Value: value1
Value value2
Value value1
Get Hashtable value: value1
Remove Hashtable value: value3
Contains Key Hashtable: true
Contains Key Hashtable: false
Contains Value Hashtable: true
Contains Value Hashtable: false
-- Example for Iterate list from Hashtable --
By Key :Key : key2 Value: value2
By Key :Key : key1 Value: value1
Value value2
Value value1
Subscribe to:
Posts (Atom)