Tuesday, January 31, 2012

JDBC example


private static Connection connectToDatabaseOrDie()
{
Connection conn = null;
try
{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost/abc";
conn = DriverManager.getConnection(url, "userName", "password");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(2);
}
return conn;
}


Tuesday, January 10, 2012

SimpleDateFormat.......list

http://docs.oracle.com/javase/1.3/docs/api/java/text/SimpleDateFormat.html

Symbol Meaning Presentation Example
------ ------- ------------ -------

G era designator (Text) AD
y year (Number) 1996
M month in year (Text & Number) July & 07
d day in month (Number) 10
h hour in am/pm (1~12) (Number) 12
H hour in day (0~23) (Number) 0
m minute in hour (Number) 30
s second in minute (Number) 55
S millisecond (Number) 978
E day in week (Text) Tuesday
D day in year (Number) 189
F day of week in month (Number) 2 (2nd Wed in July)
w week in year (Number) 27
W week in month (Number) 2
a am/pm marker (Text) PM
k hour in day (1~24) (Number) 24
K hour in am/pm (0~11) (Number) 0
z time zone (Text) Pacific Standard Time
' escape for text (Delimiter)
'' single quote (Literal) '

Monday, January 9, 2012

Date Format example in JAVA


//Program to use date format …………………
package Time;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeExample
{
public static void main(String[] args)
{
Date date = new Date();
System.out.println("Date is (with out using any date formate ==================> "+date);

SimpleDateFormat simpleDateFormate = new SimpleDateFormat("E dd.MM.yyyy 'at' hh:mm:ssa zzz");
System.out.println("SimpleDateFormat1 is (\"E dd.MM.yyyy 'at' hh:mm:ssa zzz\")===> "+simpleDateFormate.format(date));

simpleDateFormate = new SimpleDateFormat("E d.MM.y 'at' hh:mm:ssa zzz");
System.out.println("SimpleDateFormat2 is (\"E d.MM.y 'at' hh:mm:ssa zzz\") ======> "+simpleDateFormate.format(date));

simpleDateFormate = new SimpleDateFormat("EEEE dd.MMMM.yyyy 'at' hh:mm:ssa");
System.out.println("SimpleDateFormat3 is (\"EEEE dd.MMMM.yyyy 'at' hh:mm:ssa\") => "+simpleDateFormate.format(date));
}
}

OUTPUT =>
Date is (with out using any date formate ==================> Tue Jan 10 13:13:10 IST 2012
SimpleDateFormat1 is ("E dd.MM.yyyy 'at' hh:mm:ssa zzz")===> Tue 10.01.2012 at 01:13:10PM IST
SimpleDateFormat2 is ("E d.MM.y 'at' hh:mm:ssa zzz") ======> Tue 10.01.12 at 01:13:10PM IST
SimpleDateFormat3 is ("EEEE dd.MMMM.yyyy 'at' hh:mm:ssa") => Tuesday 10.January.2012 at 01:13:10PM

Wednesday, January 4, 2012