Sunday, 27 January 2013

jdbc program

Database Access with JDBC

JDBC Introduction
• JDBC provides a standard library for accessing relational databases – API standardizes
• Way to establish connection to database
• Approach to initiating queries
• Method to create stored (parameterized) queries
• The data structure of query result (table) – Determining the number of columns – Looking up metadata, etc. – API does not standardize SQL syntax
• You send strings; JDBC is not embedded SQL
– JDBC classes are in the java.sql package
– JDBC stands for “Java DataBase Connectivity”
JDBC Drivers
• JDBC consists of two parts:
– JDBC API, a purely
Java-based API – JDBC Driver Manager,which communicates with vendor-specific drivers that perform the real communication with the database.
• Point: translation to vendor format is performed on the client – No changes needed to server – Driver (translator) needed on client jdbc program for connecitivity program1 for create a table in sql 5.5 database
//STEP 1. Import required packages
import java.sql.*; 
 class CreateProductTable 
 { 
 public static void main(java.lang.String[ ] args) 
 { 
 try 
 { 
 Class.forName("com.mysql.jdbc.Driver"); 
 String url = "jdbc:mysql://localhost/test"; 
 Connection con = DriverManager.getConnection( url, "root", "00" ); 
 Statement statement = con.createStatement(); 
 String createProductTable = "CREATE TABLE PRODUCT1 " +  "(NAME VARCHAR(64), " +  "ID VARCHAR(32) NOT NULL, " +  "PRICE FLOAT, " +  "DESCrt VARCHAR(256), " +  "PRIMARY KEY(ID))"; 
 statement.executeUpdate( createProductTable );  } catch( Exception e ) { e.printStackTrace(); }  }  }

save it as CreateProductTable.java on location C:\Documents and Settings\amar\My Documents\jdbc> in my computer for compile command is javac CreateProductTable.java
 C:\Documents and Settings\amar\My Documents\jdbc>JAVAC CreateProductTable.java
for run it
 C:\Documents and Settings\amar\My Documents\jdbc>JAVA CreateProductTable

C:\Documents and Settings\amar\My Documents\jdbc>
program2 inserting rows in to table using jdbc
//STEP 1. Import required packages
import java.sql.*;
 class InsertProducts
 { 
 public static void main(java.lang.String[ ] args) 
 { 
 try 
 { 
 Class.forName("com.mysql.jdbc.Driver");
 String url = "jdbc:mysql://localhost/test";  
 Connection con = DriverManager.getConnection( url, "root", "00" ); 
 Statement statement = con.createStatement(); 
 statement.executeUpdate("INSERT INTO PRODUCT1 " + "VALUES ( 'UML User Guide', " + "'8-201-57168-4', 47.99, 'The UML user guide')" ); 
 statement.executeUpdate("INSERT INTO PRODUCT1 " + "VALUES ( 'Java Enterprise in a Nutshell', " + "'1-56592-483-5', 29.95, 'A good introduction to J2EE')" ); 
 con.close(); 
 statement.close(); 
 }catch( Exception e ) { e.printStackTrace(); } 
 } 
  }
save it as InsertProducts.java on location C:\Documents and Settings\amar\My Documents\jdbc> in my computer for compile command is javac InsertProducts.java
 C:\Documents and Settings\amar\My Documents\jdbc>JAVAC InsertProducts.java
for run it java InsertProducts
 C:\Documents and Settings\amar\My Documents\jdbc>JAVA InsertProducts

C:\Documents and Settings\amar\My Documents\jdbc>

program3.----------------------------- select or retrieve data from rows in to table using jdbc

//STEP 1. Import required packages

import java.sql.*;
public class SelectProducts {

	
	public static void main(String[] args) {
		
		 try 
		{ 
			Class.forName("com.mysql.jdbc.Driver");
			Connection con = DriverManager.getConnection( "jdbc:mysql://localhost/TEST", "root", "00" ); 
			Statement statement = con.createStatement( ); 
			String sql;
              sql = "SELECT NAME, PRICE FROM PRODUCT";
			ResultSet rs = statement.executeQuery("SELECT NAME, PRICE FROM PRODUCT1"); 
			while ( rs.next( ) ) 
				 { String name = rs.getString( "NAME" );
				 String price = rs.getString( "PRICE" ); 
				 System.out.println("Name: "+name+", price: "+price);
				 } 
			statement.close( ); 
			con.close( ); 
			} 
		catch( Exception e ) { e.printStackTrace( ); }
		 
		}
	}








save it as SelectProducts.java on location C:\Documents and Settings\amar\My Documents\jdbc> in my computer for compile command is JAVAC SelectProducts.java
 C:\Documents and Settings\amar\My Documents\jdbc>JAVAC InsertProducts.java
for run it java SelectProducts.java
 C:\Documents and Settings\amar\My Documents\jdbc>JAVA SelectProducts
Name: UML User Guide, price: 47.99
Name: Java Enterprise in a Nutshell, price: 29.95
Name: UML User Guide, price: 47.99
Name: UML User Guide, price: 47.99
Name: UML User Guide, price: 47.99
Name: UML User Guide, price: 47.99

C:\Documents and Settings\amar\My Documents\jdbc>

sql command

FROM BOOK

SQL important commands

1) .
1)
database command
s.no.want to use command syntax command means type these in sql output
i) CREATE DATABASE
create database [databasename]      ex ;
CREATE DATABASE EMP1;
 Query OK, 1 rows affected (0.05 sec)
ii) SHOW DATABASE
SHOW [database name];
SHOW DATABASES;
 +--------------------+
| Database           |
+--------------------+
| information_schema |
| emp                |
| emp1               |
| emp3               |
| estdatabase        |
| junkdb             |
| mysql              |
| performance_schema |
| raj                |
| students           |
| test               |
| testdatabase       |
| testdb             |
+--------------------+
13 rows in set (0.84 sec)
iii) USE OR SELECT or Switch to a database
use [db name];
USE EMP1;
mysql> USE EMP1;
Database changed
iv) To delete database
 drop database [database name];
 drop database emp1; 
 Query OK, 2 rows affected (0.23 sec)
v) Add a new column to database
 
 
vi)
 
 
vi)
 
 
2)
table command
s.no.want to use command syntax command means type these in sql output
(i) Create Table or make table in database
 CREATE TABLE [table name] (firstname VARCHAR(20));
CREATE TABLE employee (fname VARCHAR(20),lname VARCHAR(35)); 
Query OK, 0 rows affected (0.78 sec)
ii) see all the tables in the db database
 show tables; 
 +----------------+
| Tables_in_emp1 |
+----------------+
| employee       |
| employee1      |
+----------------+
2 rows in set (0.02 sec)
(iii) Manipulating Tables
totaly remove table from database 
DROP TABLE EMPLOYEE;
 Query OK, 0 rows affected (0.06 sec)
iv) To remove a column from a table
ALTER TABLE EMPLOYEE DROP fname;
 Query OK, 0 rows affected (0.33 sec)
Records: 0  Duplicates: 0  Warnings: 0
11) To see tables field formats
 describe [table name];
 describe EMPLOYEE;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| lname | varchar(35) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
1 row in set (0.03 sec)
6) To delete a table’s contents without removing the table completely
DELETE FROM EMPLOYEE;
 
7) one statement to delete the same row from more than one table:
DELETE FROM EMPLOYEE, CONFIDENTIAL WHERE empno='00201';
 
8) To retrieve a complete table
 SELECT * FROM EMPLOYEE;
 
9) all command insert one time store in a file
source books.sql 
 
10) To login (from unix shell) use -h only if needed.
# [mysql dir]/bin/mysql -h hostname -u root -p 
 
13)
 
 
14)
 
 
15)
 
 
16)
 
17)
 
 
18)
 
 
19)
 
 
2)
 
 
2)
 
 
2)
 
 
2)
 
 
2)
 
 
2)
 
 
2)
 
 
2)
 
 
1)
 
 
1)
 
 
5)
 
 
5)
 
 
5)
 
 
5)
 
 
5)
 
 
 h
 Query OK, 0 rows affected (0.05 sec)
 
 

CREATE DATABASE EMP1
 

dropping, or removing, a table from a database

DROP TABLE EMPLOYEE 
 


C:\Program Files\Java\jdk1.7.0\jre\lib\ext

classpath

if we want to run this than we use itjava program on it for it copy this code and save as FirstExample.java
//STEP 1. Import required packages

import java.sql.*;

public class FirstExample {

   // JDBC driver name and database URL

   static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; 

   static final String DB_URL = "jdbc:mysql://localhost/EMP";

   //  Database credentials

   static final String USER = "username";

   static final String PASS = "password";

  

   public static void main(String[] args) {

   Connection conn = null;

   Statement stmt = null;

   try{

      //STEP 2: Register JDBC driver

      Class.forName("com.mysql.jdbc.Driver");

      //STEP 3: Open a connection

      System.out.println("Connecting to database...");

      conn = DriverManager.getConnection(DB_URL,USER,PASS);

      //STEP 4: Execute a query

      System.out.println("Creating statement...");

      stmt = conn.createStatement();

      String sql;

      sql = "SELECT id, first, last, age FROM Employees";

      ResultSet rs = stmt.executeQuery(sql);

      //STEP 5: Extract data from result set

      while(rs.next()){

         //Retrieve by column name

         int id  = rs.getInt("id");

         int age = rs.getInt("age");

         String first = rs.getString("first");

         String last = rs.getString("last");

         //Display values

         System.out.print("ID: " + id);

         System.out.print(", Age: " + age);

         System.out.print(", First: " + first);

         System.out.println(", Last: " + last);

      }

      //STEP 6: Clean-up environment

      rs.close();

      stmt.close();

      conn.close();

   }catch(SQLException se){

      //Handle errors for JDBC

      se.printStackTrace();

   }catch(Exception e){

      //Handle errors for Class.forName

      e.printStackTrace();

   }finally{

      //finally block used to close resources

      try{

         if(stmt!=null)

            stmt.close();

      }catch(SQLException se2){

      }// nothing we can do

      try{

         if(conn!=null)

            conn.close();

      }catch(SQLException se){

         se.printStackTrace();

      }//end finally try

   }//end try

   System.out.println("Goodbye!");

}//end main

}//end FirstExample

now go to start > run
type cmd and goto your file path and run it as
my file is in c: FirstExample.java so i use it command Now let us compile above example as follows:

first

C:\>javac FirstExample.java

C:\>

than use it

C:\>java FirstExample

C:\>

if output is this type if you have this type of problem

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:209)
at java.lang.ClassLoader.loadClass(ClassLoader.java:324)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:269)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:337)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:187)
at FirstExample.main(FirstExample.java:18)
it cause of my sql connectivity problem to solve this problem we use to set classpath that means we first download http://www.mysql.com/products/connector/j/. than jdbc driver connecitivity file donload and set its classpath for it first jdbc file download than open it
choose jar file and copy it and past it at this location
C:\Program Files\Java\jdk1.7.0\jre\lib\ext

now go to start

than control panel

and double click on
system

now click on
click on adbanced tab

goto enviroment variable

than on system varoables



new

write it variable name classpath
varible valueis C:\Program Files\Java\jdk1.7.0\jre\lib\ext\mysql-connector-java-5.0.8-bin.jar;.; ok and save it

now again run java file in java start > run
type cmd and goto your file path and run it as
my file is in c: FirstExample.java so i use it command Now let us compile above example as follows:

first

C:\>javac FirstExample.java

C:\>

than use it

C:\>java FirstExample

C:\>


it from there now i am sure your output will be this
Connecting to database...

Creating statement...

ID: 101, Age: 25, First: Mahnaz, Last: Fatma

ID: 102, Age: 30, First: Zaid, Last: Khan

ID: 103, Age: 28, First: Sumit, Last: Mittal

Goodbye!

Classpath in Java is path to directory or list of directory which is used by ClassLoaders to find and load class in Java program. Classpath can be specified using CLASSPATH environment variable which is case insensitive, -cp or -classpath command line option or Class-Path attribute in manifest.mf file inside JAR file in Java.  In this Java tutorial we will learn What is Classpath in Java, how Java resolve classpath and How Classpath works in Java along side How to set classpath for Java in windows and UNIX environment.  I have experience in finance and insurance domain and Java is heavily used in this domain for writing sophisticated Equity, Fixed income trading applications. Most of these investment banks has written test as part of there core Java interview questions and I always find at least one question related to CLASSPATH in Java on those interviews. Java CLASSPATH is one of the most important concepts in Java,  but,  I must say mostly overlooked. This should be the first thing you should learn while writing Java programs because without correct understanding of Classpath in Java you can't understand how Java locates your class files. Also don't confuse Classpath with PATH in Java, which is another environment variable used to find java binaries located in JDK installation directory, also known as JAVA_HOME. Main difference between PATH and CLASSPATH is that former is used to locate Java commands while later is used to locate Java class files.

So let’s start with basic and then we will see some example and improvisation of Classpath in Java. In fact CLASSPATH is an environment variable which is used by Java Virtual Machine to locate user defined classes. As I said In this tutorial we will see How to setup classpath for java in windows and Linux , java -classpath example in different scenario and use of java -classpath or java -cp.

Setting Java Classpath in Windows

In order to set Classpath for Java in Windows (any version either Windows XP,  Windows 2000 or Windows 7) you need to specify value of environment variable CLASSPATH, name of this variable is not case sensitive and it doesn’t matter if name of your environment variable is Classpath, CLASSPATH or classpath in Java.

Here is Step by Step guide for setting Java Classpath in Windows:
    How to se Java Classpath in windows and Unix Linux
  1. Go to Environment variable window in Windows by pressing "Windows + Pause “-->Advanced -->Environment variable " or you can go from right click on my computer than choosing properties and then Advanced and then Environment variable this will open Environment variable window in windows.
  2. Now specify your environment variable CLASSPATH and put the value of your JAVA_HOME\lib and also include current directory by including (dot or period sign).
  3. Now to check the value of Java classpath in windows type "echo %CLASSPATH" in your DOS command prompt and it will show you the value of directory which are included in CLASSPATH.

    You can also set classpath in windows by using DOS command like :

    set CLASSPATH=%CLASSPATH%;JAVA_HOME\lib;
    This way you can set classpath in Windows XP, windows 2000 or Windows 7 and 8, as they all come with command prompt.

Setting Java Classpath in UNIX or Linux

To set Classpath for Java In Linux you can simply export CLASSPATH="your classpath" from either your .bash_profile or .bashrc script which will run whenever you login into your Linux or Unix Machine. Now to check value of Java CLASSPATH in Linux type "echo ${CLASSPATH}" this will print value of Classpath in command prompt. By using export command you can set classpath for Java in Unix, Linux, Solaris, IBM AIX or any other UNIX operating system. I hope this example for setting classpath in Java will enable to set classpath by yourself let me know if you face any problem while setting up classpath in Java

Overriding Classpath in Java

You can override classpath in Java, defined by environment variable CLASSPATH by providing option "-cp" or "-classpath" while running Java program and this is the best way to have different classpath for different Java application running on same Unix or Windows machine, standard way to define classpath for Java application is creating start-up script for Java program and set classpath there as shown below :

CLASSPATH=/home/tester/classes
java -cp $CLASSPATH Test

By default Java CLASSPATH points to current directory denoted by "." and it will look for any class only in current directory.

Different example of using Classpath in Java

In case you have multiple directories defined in CLASSPATH variable, Java will look for a class starting from first directory and only look second directory in case it did not find the specified class in first directory. This is extremely useful feature of Classpath in java to understand and it’s very useful while debugging Java application or  patch release kind of stuff. Let’s see  java -classpath example

I have set my classpath environment variable as CLASSPATH=/home/tester/first:/home/tester/second. Now I have Test class of different version in both first and second directory. When I give a command "java Test" What will happen ? Which Test class would be picked? Since JVM search directory in the order they have listed in CLASSPATH variable it will first go to the "first" directory and if it finds Test.class over there it will not go to /home/tester/second directory. Now if you delete Test.class from /home/tester/first directory it will go to /home/tester/second directory and will pick  Test.class from there.

I have used this feature of Java Classpath to test my patch releases, we used to have a folder called "patch" listed as first element in Java CLASSPATH and any point of time we want to put any debug statement or want to test any bug we just modify Java source file , compile it and generate class file and put that inside patch folder instead of creating JAR file and releasing whole new Java application. This is very handy if you are working in a large project where you don't have development environment setup in Windows and your project only runs on Unix server. This approach is much faster than remote debugging Java application in Eclipse

Its also worth noting that when you use the  java -jar command line option to run your Java program as an executable JAR, then the CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored. In this case you can set your Java classpath in the META-INF/MANIFEST.MF file by using the Class-Path attribute. In short Class-path attribute in manifest file overrides classpath specified by -cp, -classpath or CLASSPATH environment variable.

Now a common question if I have my CLASSPATH variable pointing to current directory "." and I have class called "Test" inside package "testing" and with below directory structure C:\project\testing\Test.class in my computer.

What will happen if I run command "java Test" from directory "C:\project\testing\"? will it run?
No it will not run it will give you :
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Since name of the class is not Test, instead it’s testing.Test even though your classpath is set to current directory.

Now what will happen if I give command  java testing.Test from C:\project\testing\ it will again not run and give error?

Exception in thread "main" java.lang.NoClassDefFoundError: testing/Test

Why because now it looking for class called Test which is in package testing, starting from current directory "." but don't find it since there is no directory called "testing after this path "C:\project\testing\".

To run it successfully you need to go back to directory  C:\project and now run
C:\project>java testing.Test  and It will run successfully because of Classpath issues i prefer to use Eclipse rather than running Java program from command prompt.

Errors related to Classpath in Java

If you are working in Java you must have faced some errors and exception related to classpath in java, two most common issues related to java classpath is ClassNotFoundException and NoClassDefFoundError. I have seen that many Java developer tries to solve this error by trial and error; they just don’t look beyond the hood and try to understand what the reason for these java classpath related errors is. They often misunderstood that these two errors are same also.

Here is the reason of these Java classpath errors:

ClassNotFoundException is an Exception and will be thrown when Java program dynamically tries to load a Java class at Runtime and don’t find corresponding class file on classpath. Two keyword here “dynamically” and “runtime”. Classic example of these errors is whey you try to load JDBC driver by using Class.forname(“driver name”) and greeted with java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
. So this error essentially comes when Java try to load a class using forName() or by loadClass() method of ClassLoader. Key thing to note is that presence of that class on Java classpath is not checked on compile time. So even if those classes are not present on Java classpath your program will compile successfully and only fail when you try to run.

On the other hand NoClassDefFoundError is an Error and more critical than ClassNotFoundException which is an exception and recoverable. NoClassDefFoundError comes when a particular class was present in Java Classpath during compile time but not available during run-time. Classic example of this error is using log4j.jar for logging purpose and forgot to include log4j.jar on classpath in java during run-time. to read more about logging in Java see . Keyword here is,  class was present at compile time but not available on run-time.  This is normally occurring due to any method invocation on a particular class which is part of library and not available on classpath in Java. This is also asked as common interview questions as  
What is difference between NoClassDefFoundError and ClassNotFoundException Exception in Java”   or
“When do you see NoClassDefFoundError and ClassNotFoundException Exception in Java”. By the way NoClassDefFoundError can also comes due to various other reason like static initializer failure or class not visible to Classloaders in J2EE environment. read 3 ways to resolve NoClassDefFoundError in Java for complete details.


Summary of CLASSPATH in Java

1.      Classpath in Java is an environment variable used by Java Virtual machine to locate or find  class files in Java during class loading.

2.      You can override value of Classpath in Java defined by environment variable CLASSPATH by providing JVM command line option –cp or –classpath while running your application.

3.      If two classes with same name exist in Java Classpath then the class which comes earlier in Classpath will be picked by Java Virtual Machine.

4.      By default CLASSPATH in Java points to current directory denoted by "." and it will look for any class only in current directory.

5.      When you use the -jar command line  option to run your program as an executable JAR, then the Java CLASSPATH environment variable will be ignored, and also the -cp and -classpath switches will be ignored and In this case you can set your java classpath in the META-INF/MANIFEST.MF file by using the Class-Path attribute.

6.      In Unix of Linux Java Classpath contains names of directory with colon “:” separated , On Windows Java Classpath will be  semi colon “;” separated while if you defined java classpath in Manifest file those will be space separated.

7.       You can check value of classpath in java inside your application by looking at following system property java.class.path”  System.getProperty("java.class.path")

Class-Path attribute is used to contain classpath inside manifest file. Also make sure that your manifest file must end with a blank line (carriage return or new line) , here is an example of java classpath in manifest file.

Main-Class: com.classpathexample.Demo_Classpath
Class-Path: lib/tibco.jar lib/log4j.jar


8.       It’s also important to note that path specified in manifest file is not absolute instead they are relative from application jar’s path. For example in above if your application jar file is in C:\test directory you must need a lib directory inside test and tibco.jar and log4j.jar inside that.

9.       ClassNotFoundException is an Exception and will be thrown when Java program dynamically tries to load a particular Class at Runtime and don’t find that on Java classpath due to result of Class.forName() or loadClass() method invocation.

10. NoClassDefFoundError comes when a particular class was present in Java Classpath during compile time but not available during runtime on Classpath in Java.

Friday, 18 January 2013


<html>

<body style="background-color:lightpink">
<abbr title="United Nations">UN</abbr>
<br />
HTML Paragraphs
<p>This is a paragraph.</p>
HTML Links
<a href="http://www.w3schools.com">This is a link to the
w3schools Web site.</a>



HTML Images
<img src="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\gd.png" width="104" height="142" />

Create a link attached to an image:
<a href="default.htm" target="_blank">
<img src="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\gd.png" alt="HTML tutorial" width="32"
height="32"  />
</a></p>




<acronym title="World Wide Web">WWW</acronym>
<p>The title attribute is used to show the spelled-out
version when holding the mouse pointer over the acronym
or abbreviation.</p>




<a href="lastpage.htm" target="_top">Last Page</a>
<p>
If you set the target attribute of a link to "_blank",
the link will open in a new window.
</p>




<body>
<h1 style="font-family:vivaldi">A heading</h1>
<p style="font-family:courier new; color:red; fontsize:
20px;">A paragraph</p>


<p><font size="2" face="Verdana">
This is a paragraph.
</font></p>

<p><font size="5" face="Times" color="red">

<a href="lastpage.htm">
internal link</a>
</font></p>


<h1 style="text-align:center">This is heading 1</h1>
refrance link
<a href="http://www.microsoft.com/">
This text</a>

Background Images
<body backgroun="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\da.jpg">
<h3>Look: A background image!</h3>
<body backcolor="gray">

Aligning Images
<img src="hackanm.gif" align="middle" width="48" height="48"/>
in the middle.</p>
align="top"
align="bottom"
align="right"
align="left"
width="70" height="70"
hi
alt tag
<img src="C:\Documents and Setting\amar\My Documents\My Pictures\2011-11\da.jpg" alt="Big Boat" width="200" height="50" />
<img src="../constr4.gif" alt=”Site_Under_Construction”
width="200" height="50" />
Floating Images



image map
<img src= "planets.gif" width="70" height="70" alt = planets usemap="#planetmap"/>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt= "sun" href="sun.html">
<area shape="circle" coords="0,0,82,126" alt= "sun" href="moon.html">

table


<table>
<tr>
<td>100</td>
</tr>
<td>
<td>

<table border="1">
<th>Heading</th><th>Heading</th>
<tr><th>Heading1</th>
<td>100</td><td>hi</td>
hi
<ul>
<li> bannas</li>
</ul>
</tr><tr><th>Headingl</th>
<th>Heading</th>

</table>
Table headings
<th>Heading</th>


Open a Link in a New Browser Window
<a href="lastpage.htm" target="_blank">Last Page</a>

_self
_parent
_top
_framename
_




table
Cell Padding
<h4>Without cellpadding:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellpadding:</h4>
<table border="1" cellpadding="10">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>

<p>
Cell Spacing</p>

<h4>Without cellspacing:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellspacing:</h4>
<table border="1" cellspacing="10">
<tr>
<td>First</td>
<td>Second</td>
<td>Row</td>
</tr>
</table>





table color and background and image

<table border="1" bgcolor="red">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>

<table border="1" cellspacing="10" background="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\gd.png"  >
<tr>
<td>First</td>
<td>Second</td>
<td>Row</td>
</tr>
</table>


CELL BACKGROUND  COLOR AND IMAGE

<table border="1" cellspacing="10" >
<tr>
<td background="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\gd.png">First</td>
<td bgcolor="red">Second</td>
<td>Row</td>
</tr>
</table>






ALINGING CELL CONTENTS

<table border="1" cellspacing="10" WIDTH="400">
<tr>
<td background="C:\Documents and Settings\amar\My Documents\My Pictures\2011-11\gd.png">First</td>
<td bgcolor="red">Second</td>
<td ALIGN="LEFT">RKHKLFJHGFw</td>
<td>Row</td>
</tr>
</table>





frame Attribute
<h4>With frame="border":</h4>
<table frame="border">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="box":</h4>
<table frame="box">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="void":</h4>
<table frame="void">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr></table>






<h4>With frame="above":</h4>
<table frame="above">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="below":</h4>
<table frame="below">

<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>

HSIDES<B>
<P>
<tr><table frame="HSIDES"><tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>

<H4>GSDGSSSSSSSSSS</H4>

<table frame="vsides">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="lhs":</h4>
<table frame="lhs">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With frame="rhs":</h4>
<table frame="rhs">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>


This is a mail link:
<a href="mailto:someone@microsoft.com?subject=Hello%20
again">
Send Mail</a>
</p>

<a href="mailto:someone@microsoft.com?cc=someoneelse@
microsoft.com&bcc=andsomeoneelse2@microsoft.
com&subject=Summer%20Party&body=You%20are%20invited%20
to%20a%20big%20summer%20party!">Send mail!</a>
</p><img src="boat.gif" alt="Big Boat" />






<H4>
LIST</H4>

<H4>
LIST BULLETS</H4>

<ul TYPE="CIRCLE">
<li> bannas</li>
</ul>

<ul TYPE="DISK">
<li> bannas</li>
</ul>
<ul TYPE="SQUARE">
<li> bannas</li>
</ul>


<H4>
LIST ORDERD LIST</H4>

<Ol>
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>


<H4>
DIFFERENT TYPE OF ORDERD LIST</H4>
<Ol TYPE="a">                                                
<li> bannas</li>      
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>
<Ol TYPE="A">
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>


<Ol TYPE="i">                                                
<li> bannas</li>      
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>

<Ol TYPE="I">                                                
<li> bannas</li>      
<li> bannas</li>
<li> bannas</li>
<li> bannas</li>


</Ol>


<H4>
DEFINATION LIST </H4>

<DL>
<Dt>COFEE</Dt>
<Dd>fsfsd</Dd>




nested lists












FORMS AND INPUT TAGS
<form action="">
First name:
<input type="text" name="firstname" />
<br />
Last name:
<input type="text" name="lastname" />
</form>
<H4 ALIGN="CENTER">
CHECK BOX</H4>


<form action="">
First name:
<input type="CHECKBOX" name="firstname" VALUE="BIKE" />
<br />
Last name:
<input type="CHECKBOX" name="lastname" VALUE="CAR" />
</form>

<H4 ALIGN="CENTER">
Radio Buttons</H4>
<form action="">
Male:
<input type="radio" checked="checked"
name="Sex" value="male">
<br>
Female:
<input type="radio"
name="Sex"value="female">
</form>

<H4 ALIGN="CENTER">
Drop-Down List</H4>

<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>

a value preselected on the list

<form action="">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected="selected">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>

<H4 ALIGN="CENTER">
Text Area</H4>
<textarea rows="10" cols="30"> The cat was playing in the
garden. </textarea>


<H4 ALIGN="CENTER">
Buttons</H4>

<form action="">
<input type="button" value="Hello world!">
</form>

<H4 ALIGN="CENTER">
Fieldset</H4>


<fieldset>
<legend>
Health information:
</legend>
<form action="">
Height <input type="text" size="3">
Weight <input type="text" size="3">
</form>
</fieldset>


<H4 ALIGN="CENTER">
action Attribute</H4>

<form name="input" action="html_form_submit.asp"
method="get">
Username:
<input type="text" name="user" />
<input type="submit" value="Submit" />
</form>

<H4 ALIGN="CENTER">
Form Examples</H4>

<form name="input" action="html_form_action.asp"
method="get">
Type your first name:
<input type="text" name="FirstName" value="Mickey" size="20">
<br>Type your last name:
<input type="text" name="LastName" value="Mouse" size="20">
<br>
<input type="submit" value="Submit">
</form>
<p>
If you click the "Submit" button, you will send your input
to a new page called html_form_action.asp.

Form with Check Boxes
<form name="input" action="html_form_action.asp"
method="get">
I have a bike:
<input type="checkbox" name="vehicle" value="Bike"
checked="checked" />
<br />
I have a car:
<input type="checkbox" name="vehicle" value="Car" />
<br />
I have an airplane:
<input type="checkbox" name="vehicle" value="Airplane" />
<br /><br />
<input type="submit" value="Submit" />
</form>


<form name="input" action="html_form_action.asp"
method="get">
Male:
<input type="radio" name="Sex" value="Male"
checked="checked">
<br>
Female:
<input type="radio" name="Sex" value="Female">
<br>
<input type ="submit" value ="Submit">
</form>



<H4 ALIGN="CENTER">
Send E-Mail from a Form</H4>


<form action="MAILTO:someone@w3schools.com" method="post"
enctype="text/plain">
<h3>This form sends an e-mail to W3Schools.</h3>
Name:<br>
<input type="text" name="name"
value="yourname" size="20">
<br>
Mail:<br>
<input type="text" name="mail"
value="yourmail" size="20">
<br>
Comment:<br>
<input type="text" name="comment"
value="yourcomment" size="40">
<br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset"><form action="MAILTO:someone@w3schools.com" method="post"
enctype="text/plain">
<h3>This form sends an e-mail to W3Schools.</h3>
Name:<br>
<input type="text" name="name"
value="yourname" size="20">
<br>
Mail:<br>
<input type="text" name="mail"
value="yourmail" size="20">
<br>
Comment:<br>
<input type="text" name="comment"
value="yourcomment" size="40">
<br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">

</form>





<H4 ALIGN="CENTER">
COLOR TYPE WITH TAG</H4>





<table border="2" bgcolor="TEAL">
<tr>
<TH>COLOR</TH>
<td>COLOR HEX</td>
<td>COLOR RGB</td>
<tr><td>RED</td><td>#FF0000</td><td>RGB(255,0,0)</td></tr><tr><td>GREEN</td><td>#00FF00</td><td>RGB(0,255,0)</td></tr></tr><td>BLACK</td><td>#000000</td><td>RGB(0,0,0)</tr>
<tr><td>YELLOW</td><td>#FFFF00</td><td>RGB(255,255,0)</td></tr><tr><td>CYAN</td><td>#00FFFF</td><td>RGB(0,255,255)</td></tr><td>GRAY</td><td>#C0C0C0</td><td>RGB(192,192,192)</tr></tr><tr><td>WHITE</td><td>#FFFFFF</td><td>RGB(255,255,255)</tr>
</tr><tr><td>BLUE</td><td>#0000FF</td><td>RGB(0,0,255)</td></tr>

</table>


<P STYLE=BG-COLOR="GRAY">HI






















<frameset cols="145%,75%">
<frame src="E:\ALL PUNJABI VIDEO\ram.htm">
<frame src="audio.html">
</frameset>



<iframe src="default.asp"></iframe>

</BODY>

<frameset COLs="25%,50%,25%">
<frame  src="I:\wep page\search_2.htm">
<frame src="frame_b.htm">
<frame src="frame_c.htm">
</frameset>




</html>