Java J2ME JSP J2EE Servlet Android

Avoid large white space in blogger/blogspot before table/ Table problem

If you want to use table in blogspot blog and many other blogs using <table> as following way..
<table>

<tr>
<td></td>
<td></td>
<td></td>
</tr>

<tr>
<td></td>
<td></td>
<td></td>
</tr>

</table>

You'll see a large white spaces before the table. This is for each time you press [ENTER] for new line blogspot generates a line break <br> and when you view the blog you'll find a whitespace for each <br> before the table.

If you want to avoid this unwanted white space just use the following code

<style type="text/css">.eatbr be{ display: none }</style>
<div class="eatbr">
PUT YOUR CODE FOR TABLE HERE
</div>

This will eat <br> inside it..

Happy Blogging...

JAVA: Accessing properties file(resource) inside jar

You can not load a properties file inside a jar as following way..


Properties props = new Properties();
props.load(new FileInputStream("conf.properties"));


In this case you have to use

Properties props = new Properties();
InputStream in = this.getClass().getClassLoader().getResourceAsStream("conf.properties");
props.load(in);


I hope this will help you. For any other query you can post question as comment.

Oracle DATE to TIMESTAMP

The is a function in oracle name to_timestamp that can transform from CHAR to TIMESTAMP. We can not transform a DATE to TIMESTAMP properly.
Lets consider a table mytab as follows-
mytab
name(CHAR(100)) bdate (DATE)
------------------------------------------------
Mr. Abc 10-10-2009 10:22:22 AM

If we use
SELECT TO_TIMESTAMP(bdate,'DD-MM-RRRR HH24:MI:SS') FROM mytab
we get the value of TO_TIMESTAMP(bdate,'DD-MM-RRRR HH24:MI:SS') as 10-10-2009 00:00:00 AM instead of 10-10-2009 10:22:22 AM. To get proper value of bdate in TIMESTAMP we can first change the DATE to CHAR then CHAR to TIMESTAMP as follows
TO_TIMESTAMP(TO_CHAR(bdate,'DD-MM-RRRR HH24:MI:SS'),'DD-MM-RRRR HH24:MI:SS') FROM mytab

So now
SELECT TO_TIMESTAMP(TO_CHAR(bdate,'DD-MM-RRRR HH24:MI:SS'),'DD-MM-RRRR HH24:MI:SS') FROM mytab
Will give us the value of bdate as TIMESTAMP as 10-10-2009 10:22:22 AM.


I expect your comment on this topic and other questions relating to this topic...

A way in java to user bangla number format

The following method will format a double number as thousand lac crore method
with 2 digits after decimal point.
for example 1234567890.987654321 will be formatted as
1,23,45,67,890.99

public static String banglaFormat(double number){
DecimalFormat format1 = new DecimalFormat("#,##0.00");
DecimalFormat format2 = new DecimalFormat("#,##");
DecimalFormat format3 = new DecimalFormat("000.00");
if(number<1000)
return format1.format(number);
double num2 = number/1000;
double num3 = number%1000;
return format2.format(num2)+","+format3.format(num3);
}

Java batch sql execution example

Here is an example of execution batch sql.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* This is a demo class for batch execution example
*
* @author Sharif Uddin
*
*/
public class BatchExmpl {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}
public void batchTest(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3307/mysql", "root", "");

String sql = "INSER INTO mytab(id,name) VALUES(?,?)";
PreparedStatement pstmt = connection.prepareStatement(sql);
for(int i=1;i<10;i++){
pstmt.setLong(1, i);
pstmt.setString(2, "Name_"+i);
pstmt.addBatch();
}
int updateCount[] = pstmt.executeBatch();
for(int i=0;i
System.out.println(updateCount[i]);
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
}

}

UNIX Command: ls

Displays a list of the contents of current directory


Synopsis

ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o] [-p] [-q] [-r] [-R] [-s] [-t] [-u] [-x] [pathnames]

ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o] [-p] [-q] [-r] [-R] [-s] [-t] [-u] [-x] [pathnames]


-a Displays all files including hidden files
-A Displays all files including hidden files. But does not display the working directory (.) or the parent directory (..).
-b Force to print non-printable characters to be in octal \ddd notation.
-c Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).
-C Multi-column output with entries sorted down the columns.
-d If an argument is a directory it only lists its name not its contents.
-f Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory.
-F Mark directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=).
-g Same as -l except the owner is not printed.
-i For each file, print the i-node number in the first column of the report.
-l Shows you huge amounts of information (permissions, owners, size, and when last modified.)
-L If an argument is a symbolic link, list the file or directory the link references rather than the link itself.
-m Stream output format; files are listed across the page, separated by commas.
-n The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the associated character strings.
-o The same as -l, except that the group is not printed.
-p Displays a slash ( / ) in front of all directories.
-q Force printing of non-printable characters in file names as the character question mark (?).
-r Reverses the order of how the files are displayed.
-R Includes the contents of subdirectories.
-s Give size in blocks, including indirect blocks, for each entry.
-t Shows you the files in modification time.
-u Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-x Displays files in columns.
-1 Print one entry per line of output.
pathnames File or directory to list.

Example

UNIX Command: pwd

This is short form of print working directoory. The command is used to display current directory

SYNOPSIS
pwd

Example
pwd
this will print something like
/usr/home

UNIX Command: cd

Changes the directory

SYNOPSIS
cs [DIRECTORY]

DIRECTORY - Name of the directory you want to enter
cd .. - Go back from current directory

Examples
cd
This will move the current directory to home directory

cd../../
This will move current directory to two step back directory

cd ../root/misc
This will move current directory to one step back then the /root/misc directory

cd misc
This will move current directory to misc directory if available

UNIX Command: chmod

Changes the file or directory permission to a user, group or others

Synopsis
chmod [OPTION] .. MODE[,MODE] .. FILE ..
chmod [OPTION] .. OCTAL-MODE FILE ..
chmod [OPTION] .. --reference=RFILE FILE ..

Options
-c, --changes
like verbose but report only when a change is made
-f, --silent, --quiet
Suppress most error messages
-v, --verbose
Output a diagnostic for every file processed
--reference=RFILE
Use RFILE's mode instead of MODE values
-R, --recursive
Change files and directories recursively
--help
Display this help and exit
--version
Output version information and exit

Permissions
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.

Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:

400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody


Example

chmod 644 file.txt
This gives the file file.txt read/write by the owner and only read by everyone else (-rw-r--r--).

chmod 755 file.txt
Gives all the rights but the capability for anyone to edit tile.txt (-rwxr-xr-x).

chmod 666 file.txt
Gives read and right permission to everyone.

UNIX Command: cat

cat is one of the most flexible command of UNIX. It can be used to create, concat and view file.

Sysnopsis
cat [OPTION] [FILE]
DESCRIPTION

Example: Create a new file address
cat >address
Sharif R#67, Dhaka -1207
Mizan R#123, Rajshahi


Example: To view the file addreaa
cat address

Example: Add text to addreaa
cat >>address
Shaila Godagari, Rajshahi

Example: To concat a file temp to another
cat temp>>address

Options
-e Print $ at the end of each line. This option must be used with -v.
-s Suppress messages pertaining to files that do not exist.
-t Display tab as ^I and form feed as ^L. This option must be used with -v.
-u Print output as unbuffered.
-v Display control characters and nonprinting characters

UNIX Common Shell Commands

Here are the commonly used UNIX shell commands

balance:
Lists remaining money in account

cat > filename
Easy way to create a file.

cat file1 >> file2
Concatenates file1 on the end of file2

cd newdir
Change current directory to "newdir"

correct filename
Corrects spelling of text in "file"

cp filename newfilename
Makes a copy of a file

date
Gives date and time

finger
Gives names & account numbers of current logins

frm
Shows who mail is from

from
shows who mail is from

help
Tells about on-line help

logout
When you are finished working

look [string]
Finds all words that match string

ls
Lists contents of current directory

mail
To read mail

mail usename
Sends mail to "user"

mkdir directory.name
Makes a directory

more filename
Prints file on screen one page at a time

mv file1 file2
Changes name of file1 to file2

passwd
Changes password

pwd
"print working directory" - Shows working directory name

quota -v
Shows account disk-space use

rm
Removes a file

tset [type]
Tells computer what type of terminal you are using

uptime
Shows number of users and load on machine

vi filename
Creates or opens file for editing

webster [word]
Gives definition, pronunciation and etymology of "word"

Java : JTable example

Here is a simple java JTable example

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneLayout;

public class MyFrame extends JFrame implements ActionListener{
JButton button = new JButton("Press me");
JScrollPane scrollpane = null;

Vector c = new Vector();
Vector r = new Vector();
Vector rs = new Vector();
JTable table = null;
public MyFrame() {
c.add("Name");
c.add("Age");
r.add("Sharif");
r.add("28");
rs.add(r);
r.add("Shaila");
r.add("23");
rs.add(r);
table = new JTable(rs,c);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 400, 400);
setLayout(new GridLayout(0,1));
scrollpane = new JScrollPane(table);
}
public void init(){
button.addActionListener(this);
getContentPane().add(button);
getContentPane().add(scrollpane);
setVisible(true);
}
public static void main(String args[]) {
MyFrame frame = new MyFrame();
frame.init();
}

public void actionPerformed(ActionEvent ac) {
System.out.println(ac.getSource());

}
}