Thursday 13 October 2011

SPM ASSIGNMENT QUESTIONS

1. What are typical Minor Milestones in the life-cycle of iteration? Explain periodic status assessments?
2. What is Configuration Control Board (CCB)? Explain?(PageNo. 179)
3. Explain Change Management? (PageNo. 172)
4. Define MTBF and maturity? Draw a graph for maturity expectation over a healthy projects life cycle? (PageNo. 198)
5. a) Explain modern software economics? (PageNo. 242)
b) Explain early risk resolution? (PageNo. 227)

6. Explain Common Subsystem Product Overview of CCPDS-R? (PageNo. 305)
7. Explain process overview? (PageNo. 310)

Monday 26 September 2011

JDBC CONNECTVITY

//JDBC
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.StringBuffer;
import java.io.IOException;
import java.io.*;
import java.sql.*;
public class AddressBookDataBase extends JFrame
{
private DataPanel myDataPanel;
private Connection dbconn;
private static int numPeople=0;
private static String info;
private static JTextArea txtInfo=new JTextArea( 8, 40 );
public AddressBookDataBase()
{
super("This is my Phone Book which calls a database, La La La");
GridLayout myGridLayout= new GridLayout(3,1);
Container p = getContentPane();
myDataPanel=new DataPanel();
p.add(myDataPanel);
myDataPanel.setLayout(myGridLayout);
try
{
String url = "jdbc:odbc:myAddressBook";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
dbconn = DriverManager.getConnection( url );
info="Connection successful\n";
}
catch ( ClassNotFoundException cnfex )
{
cnfex.printStackTrace();
info=info+"Connection unsuccessful\n" + cnfex.toString();
}
catch ( SQLException sqlex )
{
sqlex.printStackTrace();
info=info+"Connection unsuccessful\n" +sqlex.toString();
}
catch ( Exception excp )
{
excp.printStackTrace();
info=info+excp.toString();
}
txtInfo.setText(info
setSize(500,290);
setVisible(true);
}
public static void main(String args[])
{
AddressBookDataBase myAddressBookDataBase= new AddressBookDataBase();
myAddressBookDataBase.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
class DataPanel extends JPanel implements ActionListener
{
JLabel lblIDCap= new JLabel("Record Number");
JLabel lblLast=new JLabel("Last Name");
JLabel lblFirst=new JLabel("First Name");
JLabel lblPhone=new JLabel("Phone Number");
//JTextArea txtInfo=new JTextArea();
JLabel lblID=new JLabel(" "); //10 spaces
JTextField txtLast=new JTextField(10);
JTextField txtFirst=new JTextField(10);
JTextField txtPhone=new JTextField(10);
JButton btnAdd=new JButton("Add Record");
JButton btnFind=new JButton("Find Record");
JButton btnDelete=new JButton("Delete Record");
JButton btnUpdate=new JButton("Update Record");
JButton btnClear=new JButton("Clear");
JButton btnExit=new JButton("Exit");
public DataPanel()
{
JPanel myPanel = new JPanel();
JPanel myPanel2 = new JPanel();
JPanel myPanel3 =new JPanel();
myPanel.setLayout(new GridLayout (4,2)); //4 rows 2 cols
myPanel2.setLayout(new GridLayout (2,3)); //2 rows 3 cols
myPanel3.setLayout(new GridLayout(1,1)); //1 row 1 col
add(myPanel);
add(myPanel2);
add(myPanel3);
myPanel.add(lblIDCap);
myPanel.add(lblID);
myPanel.add(lblLast);
myPanel.add(txtLast);
myPanel.add(lblFirst);
myPanel.add(txtFirst);
myPanel.add(lblPhone);
myPanel.add(txtPhone);
myPanel2.add(btnAdd);
myPanel2.add(btnFind);
myPanel2.add(btnDelete);
myPanel2.add(btnUpdate);
myPanel2.add(btnClear);
myPanel2.add(btnExit);
myPanel3.add( new JScrollPane(txtInfo));
//puts txtInfo on application and allows it to scroll
btnAdd.addActionListener(this);
btnFind.addActionListener(this);
btnUpdate.addActionListener(this);
btnClear.addActionListener(this);
btnExit.addActionListener(this);
btnDelete.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
String ID=""; //must initialize to ""
String Last="";
String First="";
String Phone="";
Object source=event.getSource();
ID=lblID.getText().trim();
lblID.setText(ID);
Last=txtLast.getText().trim();
txtLast.setText(Last);
First=txtFirst.getText().trim();
txtFirst.setText(First);
Phone=txtPhone.getText().trim();
txtPhone.setText(Phone);
if (source.equals(btnAdd))
{
try {
Statement statement = dbconn.createStatement();
if ( !Last.equals( "" ) &&
!First.equals( "" ) &&
!Phone.equals("") )
{
String temp = "INSERT INTO AddressTable (" +
"Last, First, Phone" +
") VALUES ('" +
Last + "', '" +
First + "', '" +
Phone +
"')";
txtInfo.append( "\nInserting: " +
dbconn.nativeSQL( temp ) + "\n" );
int result = statement.executeUpdate( temp );
if ( result == 1 )
{ //confirming insertion
//txtInfo.append("\nInsertion successful\n");
String query="";
try
{
query = "SELECT * FROM AddressTable WHERE First='" +
First + "' AND Last= '" + Last + "'";
ResultSet rs = statement.executeQuery( query );
rs.next();
lblID.setText(String.valueOf(rs.getInt(1)));
}
catch ( SQLException sqlex )
{
txtInfo.append( sqlex.toString() );
}
}
else
{
txtInfo.append( "\nInsertion failed\n" );
txtFirst.setText( "" );
txtLast.setText( "" );
txtPhone.setText( "" );
}
}
else
txtInfo.append( "\nEnter last, first, " +
"phone and address, then press Add\n" );
statement.close();
}
catch ( SQLException sqlex )
{
txtInfo.append( sqlex.toString() );
txtFirst.setText("Entry already exists -- re-enter");
}
}
if (source.equals(btnFind))
{
try
{
if ( !Last.equals("") && !First.equals(""))
{
txtPhone.setText("Not Found");
Statement statement =dbconn.createStatement();
String query = "SELECT * FROM AddressTable " +
"WHERE First = '" +
First + "'"+
" AND Last = '" +
Last + "'";
txtInfo.append( "\nSending query: " +
dbconn.nativeSQL( query ) + "\n" );
ResultSet rs = statement.executeQuery( query );
display( rs );
statement.close();
}
else
txtLast.setText("Enter last name and First name"+
" then press Find" );
}
catch ( SQLException sqlex )
{
txtInfo.append( sqlex.toString() + sqlex.getMessage() );
}
}
if (source.equals(btnUpdate))
{
try
{
Statement statement = dbconn.createStatement();
if ( ! lblID.getText().equals(""))
{
String temp = "UPDATE AddressTable SET " +
"First='" + txtFirst.getText() +
"', Last='" + txtLast.getText() +
"', Phone='" + txtPhone.getText() +
"' WHERE id=" + lblID.getText();
txtInfo.append( "\nUpdating: " +
dbconn.nativeSQL( temp ) + "\n" );
int result = statement.executeUpdate( temp );
if ( result == 1 )
txtInfo.append( "\nUpdate successful\n" );
else {
txtInfo.append( "\nUpdate failed\n" );
txtFirst.setText( "" );
txtLast.setText( "" );
txtPhone.setText( "" );
}
statement.close();
}
else
txtInfo.append( "\nYou may only update an " +
"existing record. Use Find to " +
"\nlocate the record, then " +
"modify the information and " +
"\npress Update.\n" );
}
catch ( SQLException sqlex ) {
txtInfo.append( sqlex.toString() );
}
}
if (source.equals(btnDelete))
{
try
{
Statement statement = dbconn.createStatement();
if ( ! lblID.getText().equals(""))
{
System.out.print(lblID.getText());
String temp = "DELETE from AddressTable " +
" WHERE id=" + lblID.getText();
txtInfo.append( "\nDeleting: " +
dbconn.nativeSQL( temp ) + "\n" );

int result = statement.executeUpdate( temp );
if ( result == 1 )
{
txtInfo.append( "\nDeletion successful\n" );
}
else
{
txtInfo.append( "\nDeletion failed\n" );
txtFirst.setText( "" );
txtLast.setText( "" );
txtPhone.setText( "" );
}
statement.close();
}
else
txtInfo.append( "\nYou may only delete an " +
"existing record. Use Find to " +
"\nlocate the record, then " +
"press delete.\n" );
}
catch ( SQLException sqlex )
{
txtInfo.append( sqlex.toString() );
}
}
if (source.equals(btnClear))
{
txtLast.setText("");
txtFirst.setText("");
txtPhone.setText("");
lblID.setText("");
}
if (source.equals(btnExit))
{
System.exit(0);
}
}
public void display( ResultSet rs )
{
try
{
rs.next();
int recordNumber = rs.getInt( 1 );
if ( recordNumber != 0 )
{
lblID.setText( String.valueOf(recordNumber) );
txtLast.setText( rs.getString( 2 ) );
txtFirst.setText( rs.getString( 3 ) );
txtPhone.setText( rs.getString( 4 ) );
}
else
{
txtInfo.append( "\nNo record found\n" );
}
}
catch ( SQLException sqlex )
{
txtInfo.append( "\n*** Information Not In Database ***\n" );
}
}
}
}

Select the data from database

//Select the data from database
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
public class Update extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String url=" ";
Connection cont;
try
{
url="jdbc:odbc:AddressBook1";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cont=DriverManager.getConnection(url);
Statement statement=cont.createStatement();
String query="SELECT * FROM addresses WHERE ID= '"+ request.getParameter ("number") + "'";
ResultSet rs=statement.executeQuery(query);
while(rs.next())
{
String recnum=rs.getString(1);
if(recnum.equals(request.getParameter("number")))
{
pw.println("

Number:" +recnum+"

");
pw.println("

Name:" +rs.getString(2)+"

");
pw.println("

E-mail:" +rs.getString(4)+"

");
pw.println("

Phone:"+rs.getString(5)+"

");
}
else
{
pw.println("No record found");
}
}
statement.close();
}
catch(Exception e)
{
pw.println(e.toString());
}
}
}

Insert the data into a database

import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
public class Update extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String url=" ";
Connection cont;
try
{
url="jdbc:odbc:AddressBook1";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cont=DriverManager.getConnection(url);
Statement statement=cont.createStatement();
String query="INSERT INTO addresses Values ( '"+ request.getParameter ("number") + "','"+
request.getParameter("username")+"','"+request.getParameter("password")+"','"+ request.getParameter("email")+"','"+ request.getParameter("phone")+"')";
int result = statement.executeUpdate(query);
if (result == 1)
pw.println("Data was Inserted");
else
pw.println ("Data was not Inserted");
statement.close();
cont.close();
}
catch(Exception e)
{
pw.println(e.toString());
}
}
}

Wednesday 21 September 2011

Important Link

here i am posting a link that contains interview questions for c, c++, unix, java, jsp, javascript and etc...
http://techpreparation.com/

Sunday 11 September 2011

Handling HTTP POST Requests


Handling HTTP POST Requests
The following servlet handles an HTTP POST request. The servlet is invoked when a form on a Web page is submitted. The example contains two files. A Web page is defined in ColorPost.html and a servlet is defined in ColorPostServlet.java.

ColorPost.html

<html>
<body>
<center>
<form name="Form1" method="post"action="http://localhost:8080/servlets-examples /servlet/ColorPostServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>

ColorPostServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorPostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}

Handling HTTP Get Requests


Handling HTTP GET Requests
The following servlet handles an HTTP GET request. The servlet is invoked when a form on a Web page is submitted. The example contains two files. A Web page is defined in ColorGet.html and a servlet is defined in ColorGetServlet.java. The HTML source code for ColorGet.htm is shown in the following listing. It defines a form that contains a select element and a submit button. Notice that the action parameter of the form tag specifies a URL. The URL identifies a servlet to process the HTTP GET request.

ColorGet.html Program:

<html>
<body>
<center>
<form name="Form1"
action="http://localhost:8080/servlets-examples/servlet/ColorGetServlet">
<B>Color:</B>
<select name="color" size="1">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<br><br>
<input type=submit value="Submit">
</form>
</body>
</html>

ColorGetServlet.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ColorGetServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
{
String color = request.getParameter("color");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>The selected color is: ");
pw.println(color);
pw.close();
}
}

Tuesday 30 August 2011

SessionTracker Program

//SessionTracker
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionTracker extends HttpServlet {

      public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
     {
            res.setContentType("text/html");
            PrintWriter out = res.getWriter();

        // Get the current session object, create one if necessary
            HttpSession session = req.getSession(true);

            // Increment the hit count for this page.  The value is saved
            // in this client's session under the name "tracker.count".
            Integer count = (Integer)session.getValue("tracker.count");
            if (count == null)
                  count = new Integer(1);
            else
                  count = new Integer(count.intValue() + 1);
                session.putValue("tracker.count", count);

                out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
                out.println("<BODY><H1>Session Tracking Demo</H1>");

            // Display the hit count for this page
            out.println("You've visited this page " + count +((count.intValue() == 1) ? " time." : " times."));

            out.println("<P>");

            out.println("<H2>Here is your session data:</H2>");
            String[] names = session.getValueNames();
            for (int i = 0; i < names.length; i++)
         {
                  out.println(names[i] + ": " + session.getValue(names[i]) + "<BR>");
             }
            out.println("</BODY></HTML>");
      }
}

GetParameters Servlets Program

//GetParameters Servlets Program
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GetParameter extends HttpServlet
{
      public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException
    {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();   
            String firstName = request.getParameter("firstname");
            String middleName = request.getParameter("middlename");
            String lastName = request.getParameter("lastname");
   
            out.println("<b><font color='blue'>Your FirstName is : </font></b>"  
                              + "<b>"+ firstName +"</b>" + "<br>");
            out.println("<b><font color='blue'>Your Middle Name is : </font></b>" 
                              + "<b>"+ middleName +"</b>" + "<br>");
            out.println("<b><font color='blue'>Your Last Name is : </font></b>" 
                              + "<b>"+ lastName +"</b>");
      }
}

ExampleSessionServlet Program

//sessionservlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class ExampleSessionServlet extends HttpServlet
{
      public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
    {
            HttpSession session = request.getSession(true);
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String title = "Simple Session Servlet Example";
            Integer accessCount = new Integer(0);

            if (session.isNew())
        {
            }
        else
        {
                  Integer oldAccessCount = (Integer)session.getValue("accessCount");
                  if (oldAccessCount != null)
            {
                  accessCount = new Integer(oldAccessCount.intValue() + 1);
                  }
            }
            session.putValue("accessCount", accessCount);
     
            out.println(title + "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                            "<H2>Information on Your Session:</H2>\n" +
                            "<TABLE BORDER=1 ALIGN=CENTER>\n" +
                            "<TR BGCOLOR=\"#FFAD00\">\n" +
                            "  <TH>Info Type<TH>Value\n" +
                            "<TR>\n" +
                            "  <TD>ID\n" +
                            "  <TD>" + session.getId() + "\n" +
                            "<TR>\n" +
                            "  <TD>Creation Time\n" +
                            "  <TD>" + new Date(session.getCreationTime()) + "\n" +
                            "<TR>\n" +
                            "  <TD>Time of Last Access\n" +
                            "  <TD>" + new Date(session.getLastAccessedTime()) + "\n" +
                            "<TR>\n" +
                            "  <TD>Number of Previous Accesses\n" +
                            "  <TD>" + accessCount + "\n" +
                            "</TABLE>\n" +
                            "</BODY></HTML>");
      }
    /* By using getCreationTime() and new Date().getTime() you can set timeouts
    * for the session. If you are using JSDK 2.2 or higher then you can use
    * setMaxInactiveInterval(int interval) for setting timeouts.
    */
}

Accessing Date in Servlet - Program

//Accessing Date In Servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AccessedDateServlet extends HttpServlet
{
      public void doGet(HttpServletRequest request, HttpServletResponse response)
                                          throws ServletException, IOException
    {
        PrintWriter pw = response.getWriter();
        HttpSession session = request.getSession(true);
        Date create = new Date(session.getCreationTime());
        Date accessed = new Date(session.getLastAccessedTime());
        pw.println("ID " + session.getId());
        pw.println("Create: " + create);
        pw.println("Last Accessed: " + accessed);
        String dataName = request.getParameter("dataName");
        if (dataName != null && dataName.length() > 0) {
          String dataValue = request.getParameter("dataValue");
          session.putValue(dataName, dataValue);
        }
        String[] valueNames = session.getValueNames();
        if (valueNames != null &&  valueNames.length > 0)
    {
              for (int i = 0; i < valueNames.length; i++)
        {
                String str = valueNames[i];
                String str1 = session.getValue(str).toString();
                pw.println(str + " = " + str1);
              }
        }
      }

Monday 29 August 2011

introductiion to servlets

The Java Servlet API
The Java Servlet API is a set of Java classes which define a standard interface between a Web client and a Web servlet. Client requests are made to the Web server, which then invokes the servlet to service the request
through this interface.
The Java Servlet API is a Standard Java Extension API, meaning that it is not part of the core Java framework, but rather, is available as an add-on set of packages.
The API is composed of two packages:
javax.servlet
javax.servlet.http
The javax.servlet package contains classes to support generic
protocol-independent servlets. This means that servlets can be used for many protocols, for example, HTTP and FTP. The javax.servlet.http package extends the functionality of the base package to include specific support for the HTTP protocol. In this chapter, we will concentrate on the classes in the javax.servlet.http package.
This class defines the methods which servlets must implement, including a service() method for the handling of requests. The GenericServlet class implements this interface, and defines a generic, protocol-independent servlet. To write an HTTP servlet for use on the Web, we will use an even more specialized class of GenericServlet called HttpServlet.
HttpServlet provides additional methods for the processing of HTTP requests such as GET (doGet method) and POST (doPost method). Although our servlets may implement a service method, in most cases we will implement the HTTP specific request handling methods of doGet and doPost.