Java J2ME JSP J2EE Servlet Android

Oracle : ALTER TABLE: Add Columns

Syntax:

ALTER
TABLE

    table_name

ADD(

    column1 datatype1 constraint1,

    column2 datatype2 constraint2,

    column3 datatype3 constraint3

);

ALTER
TABLE

    emp

ADD(

    designation VARCHAR2(100) UNIQUE,

    rank NUMBER
NOT
NULL

);

This will add 2 columns to the table 'emp' named 'designation' and 'rank' with given constraints and data types


 

Java Difference between Hashtable and Hashmap / Hashtable versus Hashmap

Both Hashtable and Hashmap are Hashtable implementation of java classes. Hashtable is a basic class of java 'Collection Framework' and Hashmap is a Hashtable implementa from Map interface.
The majore differences are described below...

1. Synchronous/asynchronous: Hashtable is synchronous and Hashmap is not synchronous by default.

2. null value as key: Hashtable does not support null value as hash key but Hasmap support it.

3. Faile-safe: Iterator of Hashmap is fail-safe but Enumeration of Hashtable is not failsafe.

Perhaps this will be able to eliminate any misconception about Hashtable and Hashmap

Java Dangling meta character, PatternSyntaxException

PatternSyntaxException: Unmatched closing ')',

PatternSyntaxException: Unclosed group near,

PatternSyntaxException: Dangling meta character


 

The cause of the above Exceptions are you're trying to use meta character in Java Pattern processing, like regular expression.

The meta characters in this case are ([{\^-$|]})?*+

So if you want to process a String containing any of the meta characters in regular expression procession using java regex you'll get Exception like above. To process String containing a meta character just use escape character, a fore slash('/') before that character.

Any java method that use java regex also give such errors.

For example

Let's see the code below

String input = "I live in Dhaka(agargaon), Bangladesh";

String arr[] = input.split(")");

This will give the Exception PatternSyntaxException: Unmatched closing ')',

One more such method is indexOf().


 

In this case you have ti change the above code as

String arr[] = input.split("\\)");

Or for indexOf

input.indexOf("\\)");


 


 

Using cookie in Java servlet/ jsp

Cookie is often very important in web programming. Java servlet / jsp provide a easy way to work with browser cookie.

You can easily set cookie by the following way..
<%
String myName=request.getParameter("myName");
if(myName==null) myName="";
Date now = new Date();
String timestamp = now.toString();
Cookie cookie = new Cookie ("myName",myName);
cookie.setMaxAge(2 * 365 * 24 * 60 * 60);
response.addCookie(cookie);
%>
Here a cookie name 'myName' is created with value request.getParameter("myName"). The lifetime for this cookie is set to 2 years;


You you can fetch that cookie using jsp/servlet easily by the following way
<%
String cookieName = "myName";
Cookie allCookies [] = request.getCookies ();
Cookie cook = null;
if (allCookies != null)
{
for (int i = 0; i < allCookies.length; i++)
{
if (allCookies [i].getName().equals (cookieName))
{
cook = allCookies[i];
break;
}
}
}
%>

The Cookie object cook will contain the requested cookie. And you can get the value of the cookie by calling cook.getValue() methode.

Thank you.

Using Session in JSP

Session is very important in we programming. There are many use of session in web programming. Java servlet/ Jsp provide easy way to work with session.

See the following code...
<%
Vector users = new Vector();
users.add("ABC");
users.add("BCD");
users.add("CDE");
session.setAttribute("users", users);
%>

This will set the Vector object users to session with name users.

To get values from session we can do the following..
<%
Vector users = (Vector)getAttribute("users");
for(int i=0;i<users.size();i++)
out.print((String)users.get(i)+"<br >");
%>

In this way we can handle session in JSP/servlet.

For any query just add comment..