Sunday, February 27, 2011

Use existing Database


use alertclub

This Commad is use for selecting the Existing Database.
Here alertclub is a name of Database

Delete Database


drop database alertclub

If you want use it then it show message Like:

Msg 911, Level 16, State 1, Line 1
Could not locate entry in sysdatabases for database 'ram'. No entry found with that name. Make sure that the name is entered correctly.


Update Values in Table

The UPDATE statement is used to update existing records in a table.




update log1 set uname='alertclub' where class='ABC'


Note: XYZ value update to alertclub

Truncate Table

What if we only want to delete the data inside the table, and not the table itself?
Then, use the TRUNCATE TABLE statement:
For Example:

Before Truncate
Truncate Table log1





Delete Column from Table


Here we are deleting column pas

Before Drop
Alter table log1 drop column pas

After Drop

Add New Column in a Table



Before Alter

 Alter table log1 add class varchar(10);

After Alter

Note: Here Table Name is log1

Thursday, February 24, 2011

CheckBox ItemListener

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class CheckBox extends JFrame implements ItemListener
{
    JCheckBox ch1,ch2;
    JPanel p1,p2;
    Container conn;
 
    CheckBox()
    {    
        conn=getContentPane();
        conn.setBackground(Color.WHITE);
   
        p1=new JPanel();p1.setBackground(Color.yellow);   
        p2=new JPanel();p2.setBackground(Color.red);   
     
        ch1=new JCheckBox("Blue",false);ch1.setOpaque(false);
        ch2=new JCheckBox("Red",false);ch2.setOpaque(false);

        conn.add(ch1);conn.add(ch2);
  
        ch1.addItemListener(this);ch2.addItemListener(this);
  
    }
 
    public void itemStateChanged(ItemEvent e )
    {
        if (ch1.isSelected()==true) 
        {
            conn.add(p1);p1.setBounds(30,40,50,30);
            this.repaint();    
        }
        if(ch1.isSelected()==false) 
        {
            conn.remove(p1);p1.setBounds(30,40,50,30);
            this.repaint();    
        }
        if (ch2.isSelected()==true) 
        {
            conn.add(p2);p2.setBounds(100,40,50,30);
            this.repaint();
        }
   if (ch2.isSelected()==false) 
        {
            conn.remove(p2);p2.setBounds(100,40,50,30);
            this.repaint();
        }
    } 
  
    public static void main(String[] args) 
    {
        JFrame win = new CheckBox();
        win.setTitle("CheckBox");
        win.setSize(200,120);
        win.setLayout(new FlowLayout());
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setVisible(true);
    }  
}

Output


RadioButton ItemListener

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class Radiobutton extends JFrame implements ItemListener
{
    JRadioButton first,second,third,fourth;
    JPanel p1,p2,p3,p4;
    Container conn;
 
    Radiobutton()
    {    
        conn=getContentPane();
        conn.setBackground(Color.ORANGE);
   
        p1=new JPanel();
        p1.setBackground(Color.blue);
   
        p2=new JPanel();
        p2.setBackground(Color.red);
   
        p3=new JPanel();
        p3.setBackground(Color.black);
   
        p4=new JPanel();
        p4.setBackground(Color.yellow);
   
   
        first = new JRadioButton("Blue");
        second = new JRadioButton("red");
        third = new JRadioButton("Black");
        fourth = new JRadioButton("Yellow");
 
    
        //Add on Frame
        conn.add(first);conn.add(second);conn.add(third);conn.add(fourth);
  
  
        ButtonGroup bg = new ButtonGroup();
        bg.add(first);bg.add(second);bg.add(third);bg.add(fourth);
  
        first.addItemListener(this);
        second.addItemListener(this);
        third.addItemListener(this);
        fourth.addItemListener(this);
  
    }
 
    public void itemStateChanged(ItemEvent e )
    {
        if (first.isSelected()) 
        {
            conn.add(p1);
            conn.remove(p2);conn.remove(p3);conn.remove(p4);
            p1.setBounds(40,60,30,30);
            this.repaint();
    
        }
        if (second.isSelected()) 
        {
            conn.add(p2);
            conn.remove(p1);conn.remove(p3);conn.remove(p4);
            p2.setBounds(100,60,30,30);
            this.repaint();
        }
        if (third.isSelected()) 
        {
            conn.add(p3);
            conn.remove(p2);conn.remove(p1);conn.remove(p4);
            p3.setBounds(160,60,30,30);
            this.repaint();
        }
        if (fourth.isSelected()) 
        {
            conn.add(p4);
            conn.remove(p2);conn.remove(p3);conn.remove(p1);
            p4.setBounds(220,60,30,30);
            this.repaint();
        }
   
    } 
    public static void main(String[] args) 
    {
        JFrame win = new Radiobutton();
  
        win.setTitle("Radiobutton");
        win.setSize(300,200);
        win.setLayout(new FlowLayout());
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        win.setVisible(true);
    }  
}
 
Output


Monday, February 21, 2011

Sorting in Descending Order

class Sorting
{
public static void main(String s[])
{
     int number[]={55,40,70,80,90,21};
     int n=number.length;
     System.out.println("Given list:");

     for(int i=0;i<n;i++)
     {
          System.out.println(" "+ number[i]);
     }
     System.out.println("\n");


 
     for(int i=0;i<n;i++)
     {
          for(int j=i+1;j<n;j++)
          {
               if(number[i]<number[j])
               {
                    //interchange values
                    int temp=number[i];
                    number[i]=number[j];
                    number[j]=temp;
               }
          }
     }


     System.out.println("sorted list in Descending Order :");

     for(int i=0;i<n;i++)
     {
          System.out.println(" "+ number[i]);
     }

     System.out.println(" ");
}
}

Output


Sunday, February 20, 2011

RightAngle Triangle

class Square
{
    public static void main(String s[])
    {
        int i,j;
        {
                for(i=0;i<5;i++)
                {
                        System.out.print("\t");
                        for(j=0;j<5;j++)
                        {
                                System.out.print("* ");
                        }
                        System.out.println("");
                }
        }
}

Output


Square

class Square
{
    public static void main(String s[])
    {
        int i,j;
        {
                for(i=0;i<5;i++)
                {
                        System.out.print("\t");
                        for(j=0;j<5;j++)
                        {
                                System.out.print("* ");
                        }
                        System.out.println("");
                }
        }
}

Output


Thursday, February 17, 2011

Read File

import java.io.*;

public class BufferedReaderDemo
{
    public static void main(String args[]) throws IOException 
    {
        FileReader fr=new FileReader("C:/Buffered.java");
        BufferedReader br=new BufferedReader(fr);
        String str;
        while((str=br.readLine())!=null)
        System.out.println(str);
        fr.close();
    }
}

Output



Write File

import java.io.*;

class BufferedWriterDemo
{
 public static void main(String args[])
 {
    try
    {
        DataInputStream in = new DataInputStream(System.in);
        FileWriter fw = new FileWriter("c:/Buffered.java");
        BufferedWriter bw = new BufferedWriter(fw);
   
        System.out.println("How many lines?");
        int numberOfLines = Integer.parseInt(in.readLine());
        String line = "";
   
        for(int i = 0; i < numberOfLines; i++)
        {
            line = in.readLine();
            bw.write(line + "\n"); // throws IOException
        }
   
        bw.close();
   
    }
    catch(Exception e)
    {
            System.out.println(" Exception : " + e);
    }
 }
}
Output


Tuesday, February 15, 2011

Enter Character

import java.util.Scanner;

public class Char
{
    public static void main(String args[])
    {
        // System.in.Read Version
        System.out.print("\n\tSystem.in.Read Version..\n\tEnter Char ==> ");
        try
        {
                char temp = (char)System.in.read();
                System.out.printf("\n\tYou Entered: " + temp + "\n");
        }
        catch(Exception exe)
        { 
                exe.printStackTrace(); 
        }
  
        // Scanner Version
                System.out.print("\n\tScanner Version..\n\tEnter Char ==> "); 
                Scanner kb = new Scanner(System.in);
                String tString = kb.next();
                char temp2 = tString.charAt(0);
                System.out.printf("\n\tYou Entered: " + temp2 + "\n");
    }
}

Output


Enter String & Integer.

import java.io.*;

public class Information
{
    public static void main(String s[])
    {
        String Name,emp;
        int a;
  
        DataInputStream in=new DataInputStream(System.in);
  
        try
        {
      
            System.out.print("\n\tEnter Your Name:");
            Name=in.readLine();
   
            System.out.print("\tEnter Your Age:");
            a=Integer.parseInt(in.readLine());
   
            System.out.print("\tEnter Your Employee Code:");
            emp=in.readLine();
   
            System.out.println("\n\t---You Entered---\n");
            System.out.println("\tName="+Name+"");
            System.out.println("\tAge="+a+""); 
            System.out.println("\tEmployee Code="+emp+"");
        }
        catch(Exception e)
        {}
    }
}
Output


Monday, February 14, 2011

Addition of Two Number

import java.io.*;

public class Add 
{
   public static void main(String s[])
   {
      int a, b,sum=0;
      DataInputStream in=new DataInputStream(System.in);
      try
      {
         System.out.print("Enter First Number:");
         a=Integer.parseInt(in.readLine());
         System.out.print("Enter Second Number:");
         b=Integer.parseInt(in.readLine());
         sum=a+b;
         System.out.println("Sum is "+sum+".");
      }
      catch(Exception e)
      {}
   }
}
Output