Monday, April 26, 2010

timestamp in sql

java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime());

Make a checkbox read-only

With a small javascript function, you can have a good looking read-only checkbox and not use the greyed disabled look.





readonly


disabled


printPage - JSP form data into a image for standard print

well if u want to take print when the button click write the script

function printPage()
{
window.print();
}



So the printer installed in ur system get load and the printout the required
page will be out.

Friday, April 23, 2010

javascript reserved/key words

JavaScript Reserved Words
break continue do for import new this void
case default else function in return typeof while
comment delete export if label switch var with

Java Keywords (Reserved by JavaScript)
abstract implements protected
boolean instanceOf public
byte int short
char interface static
double long synchronized
false native throws
final null transient
float package true
goto private

ECMAScipt Reserved Words
catch enum throw
class extends try
const finally
debugger super

Other JavaScript Keywords
alert eval Link outerHeight scrollTo
Anchor FileUpload location outerWidth Select
Area find Location Packages self
arguments focus locationbar pageXoffset setInterval
Array Form Math pageYoffset setTimeout
assign Frame menubar parent status
blur frames MimeType parseFloat statusbar
Boolean Function moveBy parseInt stop
Button getClass moveTo Password String
callee Hidden name personalbar Submit
caller history NaN Plugin sun
captureEvents History navigate print taint
Checkbox home navigator prompt Text
clearInterval Image Navigator prototype Textarea
clearTimeout Infinity netscape Radio toolbar
close innerHeight Number ref top
closed innerWidth Object RegExp toString
confirm isFinite onBlur releaseEvents unescape
constructor isNan onError Reset untaint
Date java onFocus resizeBy unwatch
defaultStatus JavaArray onLoad resizeTo valueOf
document JavaClass onUnload routeEvent watch
Document JavaObject open scroll window
Element JavaPackage opener scrollbars Window
escape length Option scrollBy
---------------------------------------------
abstract
boolean
break
byte
case
catch
char
class
const
continue
debugger
default
delete
do
double
else
enum
export
extends
false
final
finally
float
for
function
goto
if
implements
import
in
instanceof
int
interface
long
native
new
null
package
private
protected
public
return
short
static
super
switch
synchronized
this
throw
throws
transient
true
try
typeof
var
void
volatile
while
with

Spring DAO demo

import java.util.*;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.hibernate.*;
import org.hibernate.criterion.*;

public class Main {


public static void main(String[] args) {
HibernateUtil.setup("create table EVENTS ( uid int, name VARCHAR, start_Date date, duration int);");

// hibernate code start
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
EventSpringDao eventDao = (EventSpringDao) ctx.getBean("eventDao", EventSpringDao.class);
Event event = new Event();
event.setName("Name");
eventDao.saveOrUpdate(event);


HibernateUtil.checkData("select uid, name from events");
eventDao.delete(event);


// hibernate code end
}

}


/////////////////////////////////////////////////////////////////////////
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

public abstract class AbstractSpringDao extends HibernateDaoSupport{

public AbstractSpringDao() { }

protected void saveOrUpdate(Object obj) {
getHibernateTemplate().saveOrUpdate(obj);
}

protected void delete(Object obj) {
getHibernateTemplate().delete(obj);
}

protected Object find(Class clazz, Long id) {
return getHibernateTemplate().load(clazz, id);
}

protected List findAll(Class clazz) {
return getHibernateTemplate().find("from " + clazz.getName());
}
}




/////////////////////////////////////////////////////////////////////////

import java.util.List;

public class EventSpringDao extends AbstractSpringDao{
public EventSpringDao(){}

public Event find(Long id){
return (Event) super.find(Event.class, id);
}

public void saveOrUpdate(Event event){
super.saveOrUpdate(event);
}

public void delete(Event event){
super.delete(event);
}

public List findAll(){
return super.findAll(Event.class);
}
}



/////////////////////////////////////////////////////////////////////////

















/////////////////////////////////////////////////////////////////////////

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import java.util.LinkedHashSet;

public class Event implements Serializable {
private Long id;
private int duration;
private String name;
private Date startDate;

public Event() {

}

public Event(String name) {
this.name = name;
}

/**
* @hibernate.id generator-class="native" column="uid"
* @return
*/
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }

/**
* @hibernate.property column="name"
* @return
*/
public String getName() { return name; }
public void setName(String name) { this.name = name; }

/**
* @hibernate.property column="start_date"
* @return
*/
public Date getStartDate() { return startDate; }
public void setStartDate(Date startDate) { this.startDate = startDate; }

/**
* @hibernate.property column="duration"
* @return
*/
public int getDuration() { return duration; }
public void setDuration(int duration) { this.duration = duration; }

}



/////////////////////////////////////////////////////////////////////////
/**
* Represents Exceptions thrown by the Data Access Layer.
*/
public class DataAccessLayerException extends RuntimeException {
public DataAccessLayerException() {
}

public DataAccessLayerException(String message) {
super(message);
}

public DataAccessLayerException(Throwable cause) {
super(cause);
}

public DataAccessLayerException(String message, Throwable cause) {
super(message, cause);
}
}

What is the full form of a.m. and p.m.?

Ante meridian and post meridian. "Ante" is Latin for "before", "post" means after. Meridian is when the sun reaches its zenith, the highest point in its daily arc; i.e., noontime.

Sunday, April 18, 2010

Some imp SQL DBA tricks

get into cmd
go to c:>
enter sqlplus "/ AS sysdba"

ex: c:> sqlplus "/ AS sysdba"

sql:> show user

user name will be displayed

sql:> passw system

-----------------------------------

To get the scott account unlocked
'
login as "system" user

sql:> alter user scott account unlock;

sql:> passw scott

____________________________________________


to set the line size

sql:> set linesize 100;

____________________________________________

to grant permissions to users

login as sysdba

sql:> connect /as sysdba

sql:> grant all privileges to scott;

_____________________________________________

Thursday, April 15, 2010

response.sendRedirect() - Redirect to another Servlet or JSP

response.sendRedirect() - Redirect to another Servlet or JSP
Understanding Servlet redirect
response.sendRedirect sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative or absolute URL. Servlet container converts relative URL to absolute URL before sending response to client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
This code snippet shows how to redirect to another URL from a servlet. The destination can be any URL, within the same application or out of it.
Redirect to another URL within same application.
Following snippet shows how to redirect to another JSP file.
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RedirectServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

/*
* Destination, it can be any relative or context specific path.
* if the path starts without '/' it is interpreted as relative to the current request URI.
* if the path starts with '/' it is interpreted as relative to the context.
*/

String destination ="/jsp/destination.jsp";
response.sendRedirect(response.encodeRedirectURL(destination));

}
}
Redirect to another site
You can redirect to another site too.
response.sendRedirect(response.encodeRedirectURL("http://www.google.com"));
web.xml

RedirectServlet
RedirectServlet



RedirectServlet
/redirect

Redirect from JSP
Redirecting from JSP is same as above. Just put the call to response.sendRedirect() inside a scriptlet.
<% String destination ="/jsp/destination.jsp"; response.sendRedirect(response.encodeRedirectURL(destination)); %>
Difference between redirect and forward
Servlet redirect and servlet forward both are used to handle the request processing to some other URL/Servlet but there is a big difference in the way it works. The main difference is
Servlet redirect always sends a HTTP status code 303 to client along with the redirect URL. Client then sends a new request to the URL.Thus response.sendRedirect() takes one more round trip than forward where as servlet forward just forwards the request to another resource on the server and it does not take a full round trip that is why forward is some time referred as server side redirect.
The another difference is you can redirect the request to some other URL on some another site but you can not forward the request to some other URL on different site.
Servlet forward will forward the existing request to another JSP or Servlet, so all the request parameters and attributes will be available to destination servlet. However with redirect, browser sends new request to specified URL, so old request parameters and attributes will not be available to destination resource.
Browser is completely unaware of servlet forward and hence the URL in browser address bar will remain unchanged. Where as the URL in browser address bar will change to new URL when servlet redirect is used.
Reference
HttpServletResponse.sendRedirect - HttpServletResponse


ref