Tuesday, January 31, 2012

newDatabaseConnection


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javadatabase;

/**
 *
 * @author shahbaz
 */
import java.sql.*;
class Conn {
  public static void main (String[] args) throws SQLException
  {
      try{
   Class.forName ("oracle.jdbc.OracleDriver");//Class.forName is used to load a class from anywhere to the program
      }catch(ClassNotFoundException e){System.out.println("andu");}

   Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "25121987");
                        // @//machineName:port/SID,   userid,  password
   try {
     Statement stmt = conn.createStatement();
     try {
       
       ResultSet rset=stmt.executeQuery("insert into MyTable values('raja',25)");
               rset = stmt.executeQuery("select * from MyTable");
       try {
         while (rset.next()){
           System.out.println (rset.getString(1)+"\t"+rset.getString(2));
         //System.out.println (rset.getString(2));// Print col 1
       } }
       finally {
          try { rset.close(); } catch (Exception ignore) {}
       }
     }
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   }
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}
/**********nex***************/
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javadatabase;

/**
 *
 * @author shahbaz
 */
import java.sql.*;
public class Conn1 {
    public static void main(String[] args) throws SQLException
    {
       /* Connection con=null;
                Statement s=null;
                        ResultSet rs=null;*/
        try{
            Class.forName("oracle.jdbc.OracleDriver");
        
       Connection  con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system", "25121987");
        Statement s=con.createStatement();
         s.addBatch("INSERT INTO MyTable values('Rajan',30,'M')");
         
         s.addBatch("INSERT INTO MyTable values('Rajanan',31,'M')");
         //s.addBatch("SELECT * FROM MyTable");//invalid batch command
         s.executeBatch();
       /* while(rs.next())
        {
            System.out.println(rs.getString(1)); 
        }*/
    }
        catch(Exception e)
        {
            System.out.println(e);
        }
       /* finally
        {
            try{
            rs.close();
            con.close();
            s.close();
        }
            catch(Exception e)
            {
                System.out.println(e);
            }
    }*/
    }}

Monday, January 30, 2012

babylon


package javaapplication4;


import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;


public class babylon
    extends Object
    implements Runnable
{
    public static final String VERSION = "1.0";

    public static String usernameParam     = "-username";
    public static String passwordParam     = "-password";
    public static String servernameParam   = "-servername";
    public static String portnumberParam   = "-portnumber";
    public static String chatroomParam     = "-chatroom";
    public static String widthParam        = "-xsize";
    public static String heightParam       = "-ysize";
    public static String nopasswordsParam  = "-nopasswords";
    public static String locksettingsParam = "-locksettings";
    public static String autoconnectParam  = "-autoconnect";
    public static String hidecanvasParam   = "-hidecanvas";

    private babylonWindow window;
    private URL myURL = null;/* Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine.*/
    private Class thisClass = babylon.class;//Instances of the class Class represent classes and interfaces in a //running Java application
    private String name = "";
    private String password = "";
    private String host = "";
    private String port = "";
    private String room = "";
    private int windowWidth = 0;
    private int windowHeight = 0;
    private boolean requirePasswords = true;
    private boolean lockSettings = false;
    private boolean autoConnect = false;
    private boolean showCanvas = true;

    // For managing strings according to the locale
    protected babylonStringManager strings = null;


    public babylon(String[] args)throws Exception
    {
// Get a URL to describe the invocation directory
try {
   myURL = new URL("file", "localhost", "./");
}
catch (Exception E) {
   System.out.println(E);
   System.exit(1);
}

// For managing strings according to locale
strings = new babylonStringManager(myURL,
  Locale.getDefault().getLanguage());//error

// Parse our args.  Only continue if successful
if (!parseArgs(args))
   System.exit(1);

// If "username" is blank, that's OK.  However, if the server and/or
// port are blank, we'll supply some default ones here
if ((host == null) || host.equals(""))
   host = "visopsys.org";
if ((port == null) || port.equals(""))
   port = "12468";

// Open the window
window = new babylonWindow(new babylonPanel(name, password, host,
   port, showCanvas,
   myURL));

// Set the window width and height, if applicable
Dimension tmpSize = window.getSize();
if (windowWidth > 0)
   tmpSize.width = windowWidth;
if (windowHeight > 0)
   tmpSize.height = windowHeight;
window.setSize(tmpSize);

// Make the pretty icon
window.setIcon(myURL);

// Should the window prompt users for passwords automatically?
window.contentPanel.requirePassword = requirePasswords;

// Should the user name, server name, and port name be locked
// against user changes?
window.contentPanel.lockSettings = lockSettings;

// Show the window
window.show();

// Are we supposed to attempt an automatic connection?
if (autoConnect)
   window.contentPanel.connect();
else
   window.contentPanel.offline();

// Is the user supposed to be placed in an initial chat room?
if (!room.equals(""))
   if (window.contentPanel.client != null)
try {
   window.contentPanel.client.sendEnterRoom(room, false,
"");
}
catch (IOException e) {
   window.contentPanel.client.lostConnection();
   return;
}

// Done
return;
    }

    public void run()
    {
// Nothing to do here.
return;
    }

    private void usage()
    {
System.out.println("\n" + strings.get(thisClass, "usage"));
System.out.println("java babylon [" +
  usernameParam + " name] [" +
  passwordParam + " password] [" +
  servernameParam + " host] [" +
  portnumberParam + " port] [" +
  chatroomParam + " room] [" +
  widthParam + " number] [" +
  heightParam + " number] [" +
  nopasswordsParam + "] [" +
  locksettingsParam + "] [" +
  autoconnectParam + "] [" +
  hidecanvasParam + "]");
return;
    }

    private boolean parseArgs(String[] args)
    {
// Loop through any command line arguments
for (int count = 0; count < args.length; count ++)
   {
if (args[count].equals(usernameParam))
   {
if (++count < args.length)
   name = args[count];
   }

else if (args[count].equals(passwordParam))
   {
if (++count < args.length)
   password = args[count];
   }

else if (args[count].equals(servernameParam))
   {
if (++count < args.length)
   host = args[count];
   }

else if (args[count].equals(portnumberParam))
   {
if (++count < args.length)
   port = args[count];
   }

else if (args[count].equals(chatroomParam))
   {
if (++count < args.length)
   room = args[count];
   }

else if (args[count].equals(widthParam))
   {
if (++count < args.length)
   windowWidth = Integer.parseInt(args[count]);
   }

else if (args[count].equals(heightParam))
   {
if (++count < args.length)
   windowHeight = Integer.parseInt(args[count]);
   }

else if (args[count].equals(nopasswordsParam))
   requirePasswords = false;

else if (args[count].equals(locksettingsParam))
   lockSettings = true;

else if (args[count].equals(autoconnectParam))
   autoConnect = true;

else if (args[count].equals(hidecanvasParam))
   showCanvas = false;

else if (args[count].equals("-help"))
   {
usage();
return (false);
   }

else
   {
System.out.println("\n" + strings.get(thisClass,
     "unknownarg") +
  " " + args[count]);
System.out.println(strings.get(thisClass, "forusage"));

return (false);
   }
   }

return (true);
    }

    public static void main(String[] args)
    {
        try{
babylon firstInstance = new babylon(args);
        firstInstance.run();
return;
        }
        catch(Exception e){System.out.println(e+"shahbaz");}

    }
}

Sunday, January 1, 2012

Java Taglibs Apache objective Questions

1.Which of the following is/are interface:
a.Tag
b.BodyTag
c.TagSupport
d.BodyTagSupport
Answer.(a)(b)

2.doStartTag() returns:
a.EVAL_BODY_INCLUDE
B.SKIP_BODY
C.EVAL_BODY_TAG
D.all of the above
Answer:(d)


3.doEndTag() returns:
a.EVAL_PAGE
b.SKIP_PAGE
c.both
d.none
Answer:(C)

4.Which method is invoked after body content is evaluated:
a.doInitBody()
b.doAfterBody()
c.both
d.none

Answer:(b)

5.The BodyTagSupport class implements the BodyTag interface and adds additional convenience methods which is/are:
a.getter for the bodyContent property
b.getter for the previous out JSPWriter
c.both
d.none
Answer:(c)

6. Web Application handlers must reside in one of the following standard locations for Java classes:
a.in a JAR file in the /WEB-INF/lib directory
b.in a directory in the /WEB-INF/classes directory
c.both
d.none
Answer.(c)

7. If the tag is nested, the parent handler of the enclosing tag can be accessed by using:
a.TagSupport.getParent()
b.TagSupport.findAncestorWithClass(from, class)
c.both
d.none
Answer:(c)

8.TLD is:
a. Tag Library Descriptor
b. Tag library Destructor
c Tag library Deviator
d. none
Answer (a)

9.How can u locate a TLD.
a.web.xmltaglib element
b.default mapping
c.both
d.none
Answer:c

Monday, December 12, 2011

Your First Program

Don't know anything about programming don't worry as you read this blog u will learn to program within few weeks and most importantly you will enjoy it.So , you have decided to learn programming so first you need to know what is a program.A program is an implementation to an algorithm,so whats an algorithm ,it is a set of steps written to perform a particular task.like, an algorithm to add two numbers. Step 1:Take the first number. Step 2:Take the second number. Step 3: add them . Step 4:Display the result. So, to implement the above algorithm in a program you need to choose a programming language and since C is a basic programming language and yet very powerful we choose C , to start the programming. You just need to know a few things to use C,they are: 1.Variables : they store data. 2.Datatypes:they represents the type of data stored. 3.Operators: they are used for manipulations. Lets start with implementing the algorithm. int a=10; int b=20; int c=a+b; printf("%d",c);

Sunday, November 20, 2011

for each

Guess the output: public class ForEachDemo { public static void main(String args[]){ int a[]={1,8,1,1,1,1,1,1,1,1}; for(int i:a)//for each is for arrays display System.out.println(a[i]); } } Output: 8 1 8 8 8 8 8 8 8 8




Guess the output: public class ForEachDemo { public static void main(String args[]){ int a[]={1,8,1,1,1,1,1,1,1,1}; for(int i:a)//for each is for arrays display System.out.println(i); } }
output:
1 8 1 1 1 1 1 1 1 1

Sunday, November 13, 2011

processing streams

perform some sort of operation such as buffering or encoding as they reaad and write.

Data sink stream

they are used to read from or write to specialized data sink such as files pipes strings.

ec2-user@ec2 Permission denied