Q1]

import java.io.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class College extends JFrame implements ActionListener
{
 JLabel lblid,lblname,lbladdr,lblyr;
 JTextField txtid,txtname,txtaddr,txtyr;
 JButton btninsert,btnclear,btnexit;
 College()
 {
 setLayout(null);
 lblid=new JLabel("College id");
 lblname=new JLabel("College Name");
 lbladdr=new JLabel("College Address");
 lblyr=new JLabel("Year");
 txtid=new JTextField();
 txtname=new JTextField();
 txtaddr=new JTextField();
 txtyr=new JTextField();
 btninsert=new JButton("Insert");
 btnclear=new JButton("Clear");
 btnexit=new JButton("Exit");
 lblid.setBounds(20,30,100,20);
 lblname.setBounds(20,70,150,30);
 lbladdr.setBounds(20,110,150,30);
 lblyr.setBounds(20,150,150,30);
 txtid.setBounds(120,30,150,30);
 txtname.setBounds(120,70,150,30);
 14 txtaddr.setBounds(120,110,150,30);
 txtyr.setBounds(120,150,150,30);
 btninsert.setBounds(10,200,100,50);
 btnclear.setBounds(120,200,100,50);
 btnexit.setBounds(230,200,100,50);
 btninsert.addActionListener(this);
 btnclear.addActionListener(this);
 btnexit.addActionListener(this);
 add(lblid); add(txtid);
 add(lblname); add(txtname);
 add(lbladdr); add(txtaddr);
 add(lblyr); add(txtyr);
 add(btninsert);
 add(btnclear);
 add(btnexit);
 setSize(500,400);
 }
 public void actionPerformed(ActionEvent a)
 {
 try {
 if(a.getSource()==btninsert)
 {
 int id,yr;
 String nm,add;
 // load a driver
Class.forName("org.postgresql.Driver");
// Establish Connection
conn = DriverManager.getConnection("jdbc:postgresql://192.168.1.21:5432/ty90", "ty90", ""); 
PreparedStatement pst=con.prepareStatement("insert into College values(?,?,?,?)");
 id=Integer.parseInt(txtid.getText());
 nm=txtname.getText();
 add=txtaddr.getText();
 15 yr=Integer.parseInt(txtyr.getText());
 pst.setInt(1,id);
 pst.setString(2,nm);
 pst.setString(3,add);
 pst.setInt(4,yr);
 pst.executeUpdate();
//int k= JOptionPane.showMessageDialog(null,"Record Inserted Successfully");
 con.close();
/*if(k>0){System.out.println("Record Inserted..!!!");}else{System.out.println("Error..!!!");}*/ 
}
 if(a.getSource()==btnclear)
 {
 txtid.setText("");
 txtname.setText("");
 txtaddr.setText("");
 txtyr.setText("");
 }
 if(a.getSource()==btnexit)
 {
 System.exit(0);
 }
 }
 catch(Exception e)
 {
 System.out.println("Error is :"+e);
 }
 }
 public static void main(String args[])
 16 {
 new College().show();
 }
}


Q2]

import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyServlet 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();
out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
out.println("<BODY><H1>Session Timer<</H1>");
// Display the previous timeout
out.println("The previous timeout was " +
session.getMaxInactiveInterval());
out.println("<BR>");
// Set the new timeout
session.setMaxInactiveInterval(2*60*60); // two hours
// Display the new timeout
out.println("The newly assigned timeout is " + session.getMaxInactiveInterval());
out.println("</BODY></HTML>");
}
}
