Sie sind auf Seite 1von 62

Informatics Practices

INDEX

 ACKNOWLEDGEMENT
 COMPUTER NETWORKING
 OPEN SOURCE CONCEPT
 GUI PROGRAMMING – A REVIEW
 BASICS OF OBJECT ORIENTED PROGRAMMING
 ADVANCE PROGRAMMING CONCEPTS
 DATA CONNECTIVITY
 WEB APPLICATIONS
 MYSQL REVISION TOUR
 MORE ON DATABASES AND SQL
 ADVANCE RDBMS CONCEPTS
Acknowledgement

The success and final outcome of this project required a lot of guidance and assistance from many
people and I am extremely privileged to have got this all along the completion of my project. All
that I have done is only due to such supervision and assistance and I would not forget to thank
them.

I respect and thank DR. PARAMJEET KAUR for providing me an opportunity to do the project work in
B.C.M. ARYA MODEL SR. SEC SCHOOL and giving us all support and guidance which made me
complete the project duly. I am extremely thankful to HER for providing such a nice support and
guidance, although she had busy schedule managing the corporate affairs.

I owe my deep gratitude to our project guide MRS. AMBIKA SONI, who took keen interest on our
project work and guided us all along, till the completion of our project work by providing all the
necessary information for developing a good system.

I heartily thank our internal project guide, MRS. AMBIKA SONI, HOD, I.P. DEPARTMENT for her
guidance and suggestions during this project work.

I am thankful to and fortunate enough to get constant encouragement, support and guidance from
all Teaching staffs of I.P. which helped us in successfully completing our project work. Also, I would
like to extend our sincere esteems to all staff in laboratory for their timely support.

NIKHIL JINDAL
XII-N.M.A
Computer Networking
Question: - Find the IP addresses of at least five computers in your school.
Answer: - 172.16.6.103
172.16.0.13
172.43.6.169
172.16.3.101
172.16.5.076

Question: - Find the IP address of your school's web site.


Answer: - 212.1.210.225

Question: - Find the name of Internet Service Provider of your school.


Answer: - NEBERO
OPEN SOURCE CONCEPT
Question: - Find out which software in your school lab are open source.
Answer: -
 LibreOffice
 NetBeans
 MySQL
 Blender
 PDFCreator
 Linux
 GIMP
 Ubuntu
 OpenOffice.org
 Mozilla Firefox
 Google Chrome
 Java

Question: - Note down the category of software (system software or application software) to
which they belong to.
Answer: - Operating systems and Desktop environments: -
 Linux
 Ubuntu
Graphics and multimedia
 GIMP
 Blender
Office software
 OpenOffice.org
 PDFCreator
Internet related software
 Mozilla Firefox
 Google Chrome
Programming Related
 Java
 MySQL
 NetBeans

Question: - If any of them is application software then specify its area of application.
Answer: - Operating systems and Desktop environments: -
 Linux
 Ubuntu
Graphics and multimedia
 GIMP
 Blender
Office software
 OpenOffice.org
 PDFCreator
Internet related software
 Mozilla Firefox
 Google Chrome
Programming Related
 Java
 MySQL
 NetBeans

Question: - Search on internet about the features of MySQL and NetBeans.


Answer: -

MySQL: -

 A free, open source database that powers a wide range of web apps and tools.

 Store data in Multiple Storage Engines.

 Access database info with sql commands.


 Available on 20+ platforms, including MAC, Windows, Linux, and Unix.

 It includes support for all standard SQL data types.

NetBeans: -
o Cross-platform support.

o Multiple language support.

o NetBeans Profiler.

o Code editor.
GUI Programming – A Review
Question: - Design a GUI application in which the user enters a number in the text field and on
clicking the button the Sum of the digits of the number should be displayed in a label.

Answer: -
String a = input.getText();
String b = "";
int x=0;
for(int i=1; i>0; i++)
{
for(int j=0; j<a.length(); j++)
{
b = a.substring(j,j+1);
x = x + Integer.parseInt(b);
}
if(x>9)
{
a = String.valueOf(x);
x=0;
}
else
{
JOptionPane.showMessageDialog(this, ""+x);
break;
}
QUESTION: - Design a GUI application to accept a String from the user in a text field and print using
option pane whether it is a palindrome or not.
ANSWER:-
String a = text.getText().toLowerCase();
String b = "";
String c = "";
for(int i=0; i<a.length();i++)
{
b = a.substring(i,i+1);
c = b+c;
}
if(c.equals(a))
{

JOptionPane.showMessageDialog(this,"Palindrome");
}
else
{
JOptionPane.showMessageDialog(this,"Not a Palindrome");
}
QUESTION: - Design a GUI application to accept the cost price and selling price form the user in two
text fields then calculate the profit or loss incurred.
ANSWER:-
double a = Double.parseDouble(cp.getText());
double b = Double.parseDouble(sp.getText());
if(b>a)
{
amt.setText(""+(b-a));
res.setText("Profit:");
}
else if(a>b)
{
amt.setText(""+(a-b));
res.setText("Loss:");
}
else { JOptionPane.showMessageDialog(this,"Nor Profit Nor Loss"); }
Question: - Design a GUI application to accept a character in a text field and print in a label if that
character is a vowel: a, e, i, o, or u. The application should be case sensitive.
ANSWER: -

String a = text.getText().toLowerCase();
if(a.length()!=1) JOptionPane.showMessageDialog(this,"Enter Only One Alphabet Only");
if(a.equals("a")||a.equals("e")||a.equals("i")||a.equals("o")||a.equals("u"))
res.setText("Yes it is a Vowel");

else
res.setText("No it is not a Vowel");
Question: - Design a GUI application that repeatedly accepts numbers in a option pane and once the
typed number is 0 the maximum and minimum of all numbers typed are displayed.
Answer: -

try
{
int x=0, y=0, l=0, s=0;
int a = Integer.parseInt(JOptionPane.showInputDialog(this, "Enter Your Number"));
int b = Integer.parseInt(JOptionPane.showInputDialog(this, "Enter Your Number"));
if(a>=b) { l=a; s=b; }
else { s=a; l=b; }
area.setText("Largest Number :-" +l+ "\n" + "Smallest Number :-" +s);
do
{
a = Integer.parseInt(JOptionPane.showInputDialog(this, "Enter Your Number"));
if(a==0) { break; }
if(a>=l) { l=a; }
else if(a<s) { s=a; }
else ;
area.setText("Largest Number :-" +l+ "\n" + "Smallest Number :-" +s);
}
while (1!=0);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, "Please Enter Numbers Only");
}
}
QUESTION: - Design a GUI application in java to convert temperature from Celsius to Fahrenheit or
vice versa using radio buttons and two text fields
ANSWER : -
private void
cfActionPerformed(java.awt.event.ActionEvent evt)
{
double a =
Double.parseDouble(temp.getText());
Double x = (a*9/5)+32;
res.setText(""+x);
}
private void fcActionPerformed(java.awt.event.ActionEvent evt) {
double a = Double.parseDouble(temp.getText());
Double x = (a-32)*5/9;
res.setText(""+x);
}

QUESTION: - Design a GUI application in java to convert kilograms into grams, litres into milliliters,
rupees into paisa using combobox and text fields.
ANSWERS: -
private void box0ItemStateChanged(java.awt.event.ItemEvent evt) {
switch(box0.getSelectedIndex())
{
case 0: box1.setSelectedIndex(1);
break;
case 1: box1.setSelectedIndex(0);
break;
case 2: box1.setSelectedIndex(3);
break;
case 3: box1.setSelectedIndex(2);
break;
case 4: box1.setSelectedIndex(5);
break;
case 5: box1.setSelectedIndex(4);
break;
default : break;
}
}
private void valueCaretUpdate(javax.swing.event.CaretEvent evt) {
double a = Double.parseDouble(value.getText());
if(box0.getSelectedIndex()==0||box0.getSelectedIndex()==2)
res.setText(""+(a*1000));
else if(box0.getSelectedIndex()==1||box0.getSelectedIndex()==3)
res.setText(""+(a/1000));
else if(box0.getSelectedIndex()==4)
res.setText(""+(a*100));
else if(box0.getSelectedIndex()==5)
res.setText(""+(a/100));
else;
}
Question: - A book publishing house decided to go in for computerization. The database will be
maintained at the back end but you have to design the front end for the company. You have to
accept book code, Title, Author and Quantity sold from the user. The Price will be generated
depending upon the book code. Net price should be calculated on the basis of the discount given.
Bookseller - 25%
School - 20%
Customer - 05%
Answer: -
String a = bcode.getText();
int x =
Integer.parseInt(qsold.getText());
int y=0;
switch (a) {
case "b1": y=500;
break;
case "b2": y=750;
break;
case "b3": y=250;
break;
case "b4": y=600;
break;
case "b5": y=900;
break;
default: JOptionPane.showMessageDialog(this, "Please Enter Correct Book Code");
break;
}
if(bookseller.isSelected())
{
int z = (x*y*25/100);
dgiven.setText(""+z);
}
if(school.isSelected())
{
int z = (x*y*20/100);
dgiven.setText(""+z);
}
if(customer.isSelected())
{
int z = (x*y*5/100);
dgiven.setText(""+z);
}
Basics of Object
Oriented Programming
Question: - Create a GUI application to accept a string and display it in reverse order using the
substring() method.

Answer:
private void CheckActionPerformed(java.awt.event.ActionEvent evt) {

String reverse="";
for(int i=0; i<jTextField1.getText().length(); i++)
{
reverse=jTextField1.getText().substring(i,i+1)+reverse;
}
JOptionPane.showMessageDialog(this,reverse);
}
Question: - Create a GUI application to create random whole numbers between 2 float
numbers input by the user.
Answer: -

try
{
float a = Float.parseFloat(input1.getText());
float b = Float.parseFloat(input2.getText());
if(a>b)
{
float range = a - b +1;
int result = (int) ((int)(Math.random()*range)+b);
output.setText(result+"");
}
else if(b>a)
{
float range = b - a +1;
int result = (int) ((int)(Math.random()*range)+a);
output.setText(result+"");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, "Please Enter Number Only");
}

Question: - Create a GUI application to accept 3 numbers in separate text fields and display their
sum, average, maximum or minimum after rounding the results on the click of appropriate buttons
(There are four separate buttons - one for sum, one for average, one for maximum and one for
minimum). The result should be displayed in the fourth text field.
Answer: -
private void SumActionPerformed(java.awt.event.ActionEvent evt) {
int a = Integer.parseInt(one.getText());
int b = Integer.parseInt(two.getText());
int c = Integer.parseInt(three.getText());
int x = a+b+c;
result.setText(""+x);
}
private void

AverageActionPerformed(java.awt.event.ActionEvent evt) {
int a = Integer.parseInt(one.getText());
int b = Integer.parseInt(two.getText());
int c = Integer.parseInt(three.getText());
int x = (a+b+c)/3;
result.setText(""+x);
}
private void MinimumActionPerformed(java.awt.event.ActionEvent evt) {
int a = Integer.parseInt(one.getText());
int b = Integer.parseInt(two.getText());
int c = Integer.parseInt(three.getText());

if(a<b&&a<c)
result.setText(""+a);
else if(b<a&&b<c)
result.setText(""+b);
else if(c<a&&c<b)
result.setText(""+c);
}
private void MaximumActionPerformed(java.awt.event.ActionEvent evt) {
int x = Integer.parseInt(one.getText());
int y = Integer.parseInt(two.getText());
int z = Integer.parseInt(three.getText());

if(x>y&&x>z)
result.setText(""+x);
else if(y>x&&y>z)
result.setText(""+y);
else if(z>x&&z>y)
result.setText(""+z);
}
Question: - Create a GUI application to accept the date (as 1), month (as a number like 3 for March)
and year (as 2010) in separate text fields and display the date in the format: dd/mm/yy. Take care
of the following points while creating the application:
 Verify the date input before displaying it in the suggested format and display error messages
wherever applicable
 The date is accepted as 1 (for the first of any month) but should be displayed as 01 in the final
format.
 The year is accepted as 2010 but displayed as 10 in the final format.
Answer: -
int d = Integer.parseInt(date.getText());
int m = Integer.parseInt(month.getText());
int y = Integer.parseInt(year.getText());

if(m==1&&m==3&&m==5&&m==7&&m==8&&m==10&&m==12)
{
if(d>32) JOptionPane.showMessageDialog(this,"Please Enter Correct Date");
}
if(m>12) { JOptionPane.showMessageDialog(this, "Please Enter Correct Month Number"); }
if(((y%4==0)||(y%400==0))&&m==2)
{
if(d>30) JOptionPane.showMessageDialog(this,"Please Enter Correct Date");
}
if(m==4&&m==6&&m==9&&m==11)
{
if(d>31) JOptionPane.showMessageDialog(this,"Please Enter Correct Date");
}
if(d>32) JOptionPane.showMessageDialog(this, "Please Enter Correct Date");
String b = String.valueOf(y).substring(2,4);
if(d<10) format.setText("0"+d);
else format.setText(d+"");

if(m<10) format.setText(format.getText()+"/0"+m+"/"+b);
else format.setText(format.getText()+"/"+m+"/"+b);
}
Advance Programming Concepts
Question: - Create an application to accept two strings - First Name and Last name from the user
and display the message Welcome with the complete name of the user.
Answer: -
private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt) {
String Fname = text1.getText();
String Lname = text2.getText();
area.setText("Welcome "+Fname+ " " +Lname);
}

Question: - Create an application to accept the radius of a circle, calculate the area and
circumference and display the results in a message box after rounding off the area and
circumference to an integer number.
Answer: -
private void AreaActionPerformed(java.awt.event.ActionEvent evt) {
int x = Integer.parseInt(input.getText());
int y = 22/7*x*x;
output.setText(""+y);
}
private void
CircumferenceActionPerformed(java.awt.event.ActionEvent evt) {
int x = Integer.parseInt(input.getText());
int y = 2*22/7*x;
output.setText(""+y);
}
Question: - Modify application to make sure that the user has not input the complete name in the
first name text field.
Answer: -
int z = 0;
String Fname = text1.getText();
String Lname = text2.getText();
for(int i=0; i<Fname.length(); i++)
{
String x = Fname.substring(i,i+1);
if(x.equals(" "))
{
z++;
break;
}
}
if(z!=0) JOptionPane.showMessageDialog(this, "Please Enter Your First Name only in Field 1");
else area.setText("Welcome "+Fname+ " " +Lname);

Question: - Modify the Case Changer application developed in the lesson to display the input text in
Title case using the substring(), toLowerCase() and toUpperCase() methods
Answer: -
output.setText(null);
String a =
input.getText().toLowerCase();
String b="";
int q=0,j;
for(int i=1; i>0; i++)
{
for(j=q; j<a.length(); j++)
{
String x = a.substring(j,j+1);
if(x.equals(" "))
{
q = j+1;
break;
}
q=j+1;
b = b+x;
}
String c = b;
b = "";
String d = c.substring(0,1).toUpperCase()+c.substring(1,c.length());
output.setText(output.getText()+d+" ");
if(q==a.length())
break;
}
Database Connectivity
Question: - Modify the SMS application developed in Chapter 5 to store the messages in a table
along with the number of characters in a message.

Answer: -
private void
inputCaretUpdate(javax.swing.event.CaretEvent
evt) {
String a = input.getText();
int x = a.length();
jLabel2.setText(x+"/200");
if(x>200)
{
save.setEnabled(false);
warning.setVisible(true);
}
else
{
save.setEnabled(true);
warning.setVisible(false);
}
}
private void saveActionPerformed(java.awt.event.ActionEvent evt) {
String x = input.getText();
int y = x.length();
try
{
Class.forName("java.sql.DriverManager");
Connection con =
(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement)con.createStatement();
String query = "insert into message values('"+x+"','"+y+"');";
st.executeUpdate(query);
JOptionPane.showMessageDialog(this, "Message Saved");
input.setText("");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}

Question: - Modify the password application developed in Chapter 5 to store the name and
password of users in a table. The application should also update the password whenever the user
modifies his password and should keep a count on how many times the password is being updated.
Answer: -
import javax.swing.JOptionPane;
import java.sql.DriverManager;
import
com.mysql.jdbc.Connection;
import
com.mysql.jdbc.Statement;
import java.sql.ResultSet;

public class Username_Password extends javax.swing.JFrame {

public Username_Password() {
initComponents();
}
public static String a;
private void LoginActionPerformed(java.awt.event.ActionEvent evt) {
a = uName.getText().toLowerCase();
String b = pwd.getText();
if(pwd.equals("")) JOptionPane.showMessageDialog(this, "please Enter Password");
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String query = "Select password from login where username = '"+a+"';";
ResultSet rs = st.executeQuery(query);
if(rs.next())
{
String password = rs.getString("password");
if(password.equals(b)) JOptionPane.showMessageDialog(this, "Login Sucessful");
else JOptionPane.showMessageDialog(this, "Invalid Password");
System.exit(0);
}
else JOptionPane.showMessageDialog(this, "UserName Not Found");
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void ChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new Password_Change().setVisible(true);
}
private void CreateAccountActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new Create_Account().setVisible(true);
}
…………………………………………………………………………………………………………………………………………………………………………………………………………..

import javax.swing.JOptionPane;
import java.sql.DriverManager;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

private void

CreateAccountActionPerformed(java.awt.event.ActionEvent evt) {
String firstName = fName.getText();
String lastName = lName.getText();
String userName = uName.getText().toLowerCase();
String DOB = dob.getText();
String country = c.getText();
String phoneNumber = pNumber.getText();
String password = pwd.getText();
if(firstName.equals("")||lastName.equals("")||userName.equals("")||DOB.equals("")
||country.equals("")||phoneNumber.equals("")||password.equals(""))
{
JOptionPane.showMessageDialog(this, "Please Enter All Fields Accordingly");
}
else
{
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String query = "insert into login
values('"+userName+"','"+firstName+"','"+lastName+"','"+DOB+"','"+country+"','"+phoneNumber+"','"
+password+"','"+0+"');";
st.execute(query);
JOptionPane.showMessageDialog(this, "Account Created");
fName.setText("");
lName.setText("");
uName.setText("");
dob.setText("");
c.setText("");
pNumber.setText("");
pwd.setText("");
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
this.setVisible(false);
new Username_Password().setVisible(true);
}
private void BackActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new Username_Password().setVisible(true);
}
…………………………………………………………………………………………………………………………………………………………………………………………………………..

import static
Connectivity_Based.Username_Password.a;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class Password_Change extends javax.swing.JFrame {
public Password_Change() {
initComponents();
warning1.setVisible(false);
}
private void ChangeActionPerformed(java.awt.event.ActionEvent evt) {
String b = uName.getText();
String x = crPassword1.getText();
String y = newPassword1.getText();
String z = confirm1.getText();
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String query = "Select password from login where username = '"+b+"';";
ResultSet rs = st.executeQuery(query);
if(rs.next())
{
String password = rs.getString("password");
if(x.equals(password)&&y.equals(z))
{
String query2 = "Update login set password = '"+y+"',Password_ChangeCount =
Password_ChangeCount+1 where username = '"+a+"';";
st.execute(query2);
JOptionPane.showMessageDialog(this, "Password Changed Sucessfully");
crPassword1.setText("");
newPassword1.setText("");
confirm1.setText("");
uName.setText("");
}
else
{
JOptionPane.showMessageDialog(this, "Please Check Your Password");
}
}
}
catch(Exception s)
{
JOptionPane.showMessageDialog(this, s.getMessage());
}
}
private void BackActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
new Username_Password().setVisible(true);
}
private void newPassword1CaretUpdate(javax.swing.event.CaretEvent evt) {
String y = newPassword1.getText();
String z = confirm1.getText();
if(!y.equals(z)) warning1.setVisible(true);
else warning1.setVisible(false);
}
private void confirm1CaretUpdate(javax.swing.event.CaretEvent evt) {
String y = newPassword1.getText();
String z = confirm1.getText();
if(!y.equals(z)) warning1.setVisible(true);
else warning1.setVisible(false);
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
uName.setText(a);
}
Question: - Design a GUI Interface for executing SQL queries for the above developed Password
Application to accomplishing the following tasks:
A. Retrieve a list of all the names and display it in a table
form.
B. Retrieve a list of names where name begins with a
specific character input by the user and display it in a
table form.
C. Display all records sorted on the basis of the names.
Answer: -
import javax.swing.table.DefaultTableModel;
import java.sql.DriverManager;
import java.sql.ResultSet;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import javax.swing.JOptionPane;

private void GetAllActionPerformed(java.awt.event.ActionEvent evt) {


DefaultTableModel m = (DefaultTableModel) jTable1.getModel();
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String a = "select FirstName,LastName from login;";
ResultSet rs = st.executeQuery(a);
while(rs.next())
{
String fName = rs.getString("FirstName");
String lName = rs.getString("LastName");
m.addRow(new Object[]{fName,lName});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void AccendingOrderActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel m = (DefaultTableModel) jTable1.getModel();
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String a = "select FirstName,LastName from login ORDER BY FirstName ASC;";
ResultSet rs = st.executeQuery(a);
while(rs.next())
{
String fName = rs.getString("FirstName");
String lName = rs.getString("LastName");
m.addRow(new Object[]{fName,lName});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
private void EnterNameActionPerformed(java.awt.event.ActionEvent evt) {
String name = input.getText();
DefaultTableModel m = (DefaultTableModel) jTable1.getModel();
try
{
Class.forName("java.sql.DriverManager");
Connection con = (Connection)
DriverManager.getConnection("jdbc:mysql://localhost:3306/Nikhil","root","");
Statement st = (Statement) con.createStatement();
String a = "select FirstName,LastName from login where FirstName like '"+name+"%';";
ResultSet rs = st.executeQuery(a);
while(rs.next())
{
String fName = rs.getString("FirstName");
String lName = rs.getString("LastName");
m.addRow(new Object[]{fName,lName});
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage());
}
}
WEB APPLICATIONS
QUESTION: - Write HTML code to display the following web pages:
ANSWER: -
<html>
<head>
<title></title>
</head>
<body>
<center><img src = "football.png"></center>
<h1>Welcome To The Website of Manchester
Football Club</h1>
<p>The Manchester Football club is based in
United States of America

and has a long and proud history. We have several teams in various age

groups from kids to grown-ups so there is a team to suit any player</p>


<br>
<U>This year's motto:</U><br>
We are the BEST
</body>
</html>
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<html>
<head>
<title></title>
</head>
<body>
<table border = "2">
<tr>
<td colspan = 2><b><font color =
"Red"><center>Fresh Fruits</b></font></center></td>
</tr>
<tr>
<td>Fresh Fruits helps us stay healthy and fit</td>
<td><img src = "football.png"></td>
</tr>
</table>
</body>
</html>
…………………………………………….…………………………………………………………………………………………………………………………………………………………….

<html>
<head>
<title></title>
</head>
<body>
<ol type = "1">
<li>INDIA
<ol type = "a">
<li>HARYANA
<ul type = "Square">
<li>Gurgaon
<li>Faridabad
</ul>
<li>J&K
<ul type = "Square">
<li>Jammu
<li>Srinagar
</ul>
</body>
</html>

…………………………………………………………………………………………………………………………………………………………………………………………………………..

<html>
<head>
<title></title>
</head>
<body>
<ol type = "a">
<li>ONE 1 2 3
<li>TWO
<ol type = "i" start = "ii">
<li>ONE
<li>TWO
<li>THREE
</ol>
<li>Things we learned in kindergarden:
<ol type = "1">
<li>share
<li>play fair
<li>don't hit people
<li>put things back where we found them
<li>say sorry when we hurt somebody
</ol>
</ol>
</body>
</html>

QUESTION: - Give the output of the following code


ANSWER: -
<HTML>
<BODY>
<H1>The following is a list of
a few chemicals: </H1>
<UL type="disc">
<LI>Sodium
<LI>Sulphur
<LI>Magnesium
</UL>
</BODY>
</HTML>
QUESTION: -
ANSWER: -
<HTML>
<HEAD>
<TITLE>SCHEDULE</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="3">
<CAPTION>VOLUNTEER SCHEDULE</CAPTION>
<TR BGCOLOR="#AAFFCC">
<TH>9 A.M.</TH>
<TH>12 P.M.</TH>
<TH>2 P.M.</TH>
</TR>
<TR>
<TD>Anmol</TD>
<TD>Abhinav</TD>
<TD>Anika</TD>
</TR>
<TR>
<TD>Riti</TD>
<TD>Riya</TD>
<TD>Sara</TD>
</TR>
<TR>
<TD>Gul</TD>
<TD>Reyana</TD>
<TD>Swayam</TD>
</TR>
</TABLE>
</BODY>
</HTML>
MySQL-Revision Tour
Question: - Consider a database LOANS with the following table:
Table: Loan_Accounts:
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R.K. Gupta 300000 36 12.00 19-07-2009
2 S.P. Sharma 500000 48 10.00 22-03-2008
3 K.P. Jain 300000 36 Null 08-03-2007
4 M.P. Yadav 800000 60 10.00 06-12-2008
5 S.P. Sinha 200000 36 12.50 03-01-2010
6 P. Sharma 700000 60 12.50 05-06-2008
7 K.s. Dhall 500000 48 null 05-03-2008

Write SQL commands for the tasks 1 to 35 and write the output for the SQL commands 36 to 40:
Create Database and use it:
1. Create the database LOANS.
2. Use the database LOANS.
Create Table / Insert Into:
3. Create the table Loan_Accounts and insert tuples in it.
Simple Select
4. Display the details of all the loans.
5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.
Conditional Select using Where Clause
6. Display the details of all the loans with less than 40 instalments.
7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.
8. Display the Int_Rate of all the loans started after 01-04-2009.
Using NULL
9. Display the details of all the loans whose rate of interest is NULL.
10. Display the details of all the loans whose rate of interest is not NULL.
Using DISTINCT Clause
11. Display the amounts of various loans from the table Loan_Accounts. A loan amount should
appear only once.
12. Display the number of instalments of various loans from the table Loan_Accounts. An
instalment should appear only once.
Using Logical Operators (NOT, AND, OR)
13. Display the details of all the loans started after 31-12-2008 for which the number of instalments
are more than 36.
14. Display the Cust_Name and Loan_Amount for all the loans which do not have number of
instalments 36.
15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount is less
than 500000 or int_rate is more than 12.
16. Display the details of all the loans which started in the year 2009.
17. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000.
18. Display the details of all the loans whose rate of interest is in the range 11% to 12%. Using IN
Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of instalments
are 24, 36, or 48. (Using IN operator) Using BETWEEN Operator
20. Display the details of all the loans whose Loan_Amount is in the range 400000 to 500000. (Using
BETWEEN operator)
21. Display the details of all the loans whose rate of interest is in the range 11% to 12%.(Using
BETWEEN operator)
Using LIKE Operator
22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
ends with 'Sharma'.
23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
ends with 'a'.
24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
contains 'a'
25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
does not contain 'P'.
26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name
contains 'a' as the second last character.
Using ORDER BY clause
27. Display the details of all the loans in the ascending order of their Loan_Amount.
28. Display the details of all the loans in the descending order of their Start_Date.
29. Display the details of all the loans in the ascending order of their Loan_Amount and within
Loan_Amount in the descending order of their Start_Date. Using UPDATE, DELETE, ALTER TABLE
30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than
400000.
32. For each loan replace Interest with (Loan_Amount*Int_Rate*Instalments) 12*100.
33. Delete the records of all the loans whose start date is before 2007.
34. Delete the records of all the loans of 'K.P. Jain'
35. Add another column Category of type CHAR(1) in the Loan table.
Find the Output of the following queries
36. SELECT cust_name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name) FROM
Loan_Accounts WHERE Int_Rate < 11.00;
37. SELECT LEFT(Cust_Name, 3), Right(Cust_Name, 3), SUBSTR(Cust_Name, 1, 3) FROM
Loan_Accounts WHERE Int_Rate > 10.00;
38. SELECT RIGHT(Cust_Name, 3), SUBSTR(Cust_Name, 5) FROM Loan_Accounts;
39. SELECT DAYNAME(Start_Date) FROM Loan_Accounts;
40. SELECT ROUND(Int_Rate*110/100, 2) FROM Loan_Account WHERE Int_Rate > 10; Write the
output produced by the following SQL commands:
41. SELECT POW(4,3), POW(3,4);
42. SELECT ROUND(543.5694,2), ROUND(543.5694), ROUND(543.5694,-1);
43. SELECT TRUNCATE(543.5694,2), TRUNCATE(543.5694,-1);
44. SELECT LENGTH("Prof. M. L. Sharma");
45. SELECT CONCAT("SHEIKH", " HAROON") "FULL NAME";
46. SELECT YEAR(CURDATE()), MONTH(CURDATE()), DAY(CURDATE());
47. SELECT DAYOFYEAR(CURDATE()), DAYOFMONTH(CURDATE()), DAYNAME(CURDATE());
48. SELECT LEFT("Unicode",3), RIGHT("Unicode",4);
49. SELECT INSTR("UNICODE","CO"), INSTR("UNICODE","CD");
50. SELECT MID("Informatics",3,4), SUBSTR("Practices",3);
Answers
1. Create database LOANS;
2. Use LOANS;
3. create table Loan_Accounts(AccNo varchar(5),Cust_Name varchar(50),Loan_Amount
integer(10),Instalments integer(10),int_Rate decimal(4,2),Start_date date,Interest
decimal(10,2));
insert into Loan_Accounts values(1,"R.K. Gupta",300000,36,12.00,"2009-07-19",null);
insert into Loan_Accounts values(2,"S.P. Sharma",500000,48,10.00,"2008-03-22",null);
insert into Loan_Accounts values(3,"K.P. Jain",300000,36,null,"2007-03-08",null);
insert into Loan_Accounts values(4,"M.P. yadav",800000,60,10.00,"2008-01-06",null);
insert into Loan_Accounts values(5,"S.P. Sinha",200000,36,12.00,"2010-01-03",null);
insert into Loan_Accounts values(6,"P. Sharma",700000,60,12.50,"2008-06-05",null);
insert into Loan_Accounts values(7,"K.S. Dhall",500000,48,null,"2008-03-05",null);

4.

5.

6.

7.
8.

9.

10.

11.

12.

13. SELECT * FROM Loan_Accounts WHERE Start_Date>’2008-12-31’ AND Instalments>36;


14.

15.

16.

17.

18.

19.
20.

21.

22.

23.

24.

25.

26.
27.

28.

29.

30.update Loan_Accounts set int_Rate = 11.50 where int_rate is null;


31.update Loan_Accounts set int_Rate = int_Rate + .05 where Loan_Amount>400000;
32.update Loan_Accounts set Interest = (Loan_Amount*Int_Rate*Instalments)/12*100;
33.delete from Loan_Accounts where year(Start_date)<2007;
34.delete from Loan_Accounts where Cust_Name = "K.P Jain";
35.Alter table Loan_Accounts add Category char(1);

36.
37.

38.

39.

40.

41.
42.

43.

44.

45.

46.

47.
48.

49.

50.
MORE ON DATABASE AND SQL
QUESTION: - In a database create the following tables with suitable constraints

ANSWER: -
1. CREATE table STUDENTS(AdmNo int(4)Primary Key,Name varchar(50),Class int(2),Sec
char(1),RNo int(2),Address varchar(100),Phone varchar(50));
2. Insert into students values(“1271”,”Utkarsh Madaan”,”12”,”C”,”1”,”C-32, Punjabi
bagh”,”4356154”);
3. Insert into students values(“1324”,”Naresh Sharma”,”10”,”A”,”1”,”31, Mohan
Nagar”,”435654”);
4. Insert into students values(“1325”,”Md. Yusuf”,”10”,”A”,”2”,”12/21, Chand Nagar”,”145654”);
5. Insert into students values(“1328”,”Sumedha”,”10”,”B”,”23”,”59, Moti Nagar”,”4135654”);
6. Insert into students values(“1364”,”Subya Akhtar”,”11”,”B”,”13”,”12, janak Puri”,null);
7. Insert into students values(“1434”,”Varuna”,”12”,”B”,”21”,”69, Rohoni”,null);
8. Insert into students values(“1461”,”David DSouza”,”11”,”B”,”1”,”D-34, Model Town”,”243554,
98787665”);
9. Insert into students values(“2324”,”Satinder Singh”,”12”,”C”,”1”,”1/2, Gulmohar
Park”,”143654”);
10.Insert into students values(“2328”,”Peter Jones”,”10”,”A”,”18”,”21/32B, Vishal
Enclave”,”24356154”);
11.Insert into students values(“2371”,”Mohini Mehta”,”11”,”C”,”12”,”37, Raja Garden”,”435654,
6765787”);
1. Create table SPORTS(AdmNo int(4),Game varchar(50),CoachName varchar(50),Grade char(1));
2. INSERT into table SPORTS values(“1324”,”Cricket”,”Narendra”,”A”);
3. INSERT into SPORTS values(“1364”,”Volleball”,”M.P. Singh”,”A”);
4. INSERT into SPORTS values(“1271”,”Volleball”,”M.P. Singh”,”B”);
5. INSERT into SPORTS values(“1434”,”Basketball”,”I. Malhotra”,”B”);
6. INSERT into SPORTS values(“1461”,”Cricket”,”Narendra”,”B”);
7. INSERT into SPORTS values(“2328”,”Basketball”,”I. Malhotra”,”A”);
8. INSERT into SPORTS values(“2371”,”Basketball”,”I. Malhotra”,”A”);
9. INSERT into SPORTS values(“1271”,”Basketball”,”I. Malhotra”,”A”);
10.INSERT into SPORTS values(“1434”,”Cricket”,”Narendra”,”A”);
11.INSERT into SPORTS values(“2328”,”Cricket”,”Narendra”,”B”);
12.INSERT into SPORTS values(“1364”,”Basketball”,”I. Malhotra”,”B”);

QUESTIONS: - Based on these tables write SQL statements for the following queries:
i. Display the lowest and the highest classes from the table STUDENTS.
ii. Display the number of students in each class from the table STUDENTS.
iii. Display the number of students in class 10.
iv. Display details of the students of Cricket team.
v. Display Admission number, name, class, section, and roll number of the students whose
grade in Sports table is 'A'.
vi. Display the name and phone number of the students of class 12 who are play some game.
vii. Display the Number of students with each coach.
viii. Display the names and phone numbers of the students whose grade is 'A' and whose
coach is Narendra.
ANSWERS: -
I. Select min(class),max(class) from STUDENTS;
II. Select class,count(class) from students group by class;
III. Select count(class) from students where class = 10;
IV. select * from students,sports where sports.admno=students.admno AND game = "Cricket";
V. select * from students,sports where sports.admno=students.admno AND game = "Cricket";
VI. select Name,Phone from students,sports where sports.admno=students.admno;
VII. select coachName,count(name) from sports,students where sports.admno=students.admno
group by coachname;
VIII. select Name,Phone from students,sports where Sports.AdmNo = Students.AdmNo AND Grade =
"A" AND CoachName = "Narendra";

QUESTIONS: - c) Predict the the output of each of the following SQL statements, and then verify the
output by actually entering these statements:
i. SELECT class, sec, count(*) FROM students GROUP BY class, sec;
ii. SELECT Game, COUNT(*) FROM Sports GROUP BY Game;
iii. SELECT game, name, address FROM students, Sports
WHERE students.admno = sports.admno AND grade = 'A';
iv. SELECT Game FROM students, Sports
WHERE students.admno = sports.admno AND Students.AdmNo = 1434;
ANSWERS: -
QUESTIONS: - In a database create the following tables with suitable constraints :
ANSWERS: -

1. create table items(I_Code int(4)Primary Key,Name varchar(50),Category varchar(50),rate


int(3));
2. insert into items values(“1001”,”Masala Dosa”,”South Indian”,”60”);
3. insert into items values(“1002”,”Vada Sambhar”,”South Indian”,”40”);
4. insert into items values(“1003”,”Idli Sambhar”,”South Indian”,”40”);
5. insert into items values(“2001”,”Chow Mein”,”Chinese”,”80”);
6. insert into items values(“2002”,”Dimdum”,”Chinese”,”60”);
7. insert into items values(“2003”,”Soup”,”Chinese”,”50”);
8. insert into items values(“3001”,”Pizza”,”Italian”,”240”);
9. insert into items values(“3002”,”Pasta”,”Italian”,”125”);
1. Create table bills(BillNo int(1),Date date,I_Code int(4),qty int(2));
2. Insert into bills values(“1”,”2010-04-01”,”1002”,”2”);
3. Insert into bills values(“1”,” 2010-04-01”,”3001”,”1”);
4. Insert into bills values(“2”,” 2010-04-01”,”1001”,”3”);
5. Insert into bills values(“2”,” 2010-04-01”,”1002”,”1”);
6. Insert into bills values(“2”,” 2010-04-01”,”2003”,”2”);
7. Insert into bills values(“3”,” 2010-04-02”,”2002”,”1”);
8. Insert into bills values(“4”,” 2010-04-02”,”2002”,”4”);
9. Insert into bills values(“4”,” 2010-04-02”,”2003”,”2”);
10. Insert into bills values(“5”,” 2010-04-03”,”2003”,”2”);
11. Insert into bills values(“5”,” 2010-04-03”,”3001”,”1”);
12. Insert into bills values(“5”,” 2010-04-03”,”3002”,”3”);
QUESTION: - a) Based on these tables write SQL statements for the following queries:
i. Display the average rate of a South Indian item.
ii. ii. Display the number of items in each category.
iii. iii. Display the total quantity sold for each item.
iv. Display total quanity of each item sold but don't display this data for the items whose total
quantity sold is less than 3.
v. Display the details of bill records along with Name of each corresponding item.
vi. Display the details of the bill records for which the item is 'Dosa'.
vii. Display the bill records for each Italian item sold.

ANSWERS: -
i. select avg(rate) from items where category = "South Indian";
ii. select category,count(category) from items group by category;
iii. select Name,sum(qty) from bills,items where items.I_Code = Bills.I_Code group by name;
iv. select Name,sum(qty) from bills,items where items.I_Code = Bills.I_Code group by name
having sum(qty)>=3;
v. Select Name,BillNo,Date,Bills.I_Code,qty from bills,items where Bills.I_Code = Items.I_Code;
vi. select Name,BillNo,Date,Bills.I_Code,qty from bills,items where Items.I_Code = Bills.I_Code
AND name like "%Dosa";
vii. select Name,BillNo,Date,Bills.I_Code,qty from bills,items where Items.I_Code = Bills.I_Code
AND Category = "Italian";

b) Identify the Foreign Keys (if any) of these tables. Justify your answer.
A. I_Code is the foreign key among these tables. This is because, I_Code is used to link the two
tables and it is a primary key for Items table.
c) Answer with justification (Think independently. More than one answers may be correct. It all
depends on your logical thinking):
i. Is it easy to remember the Category of item with a given item code? Do you find any kind of
pattern in the items code? What could be the item code of another South Indian item?
A. Yes, it is easy to remember the category of item with a given item code. There is a kind of
pattern in the item codes, South Indian dishes must be in the range from 1000 to 1999, Chinese dishes
must be in the range of 2000 to 2999 and Italian food must be in the range of 3000 to 3999.
The code of another South Indian item could be 1004.
ii. What can be the possible uses of Bills table? Can it be used for some analysis purpose?
A. The possible uses of BILLS table can be:
1. Maintenance of bill records.
2. Maintenance of sale records.
3. Legal proof.
Yes, it can be used for some analysis purpose also. We can find overtime sales of the items or a
particular item.
iii. Do you find any columns in these tables which can be NULL? Is there any column which must not
be NULL?
A. No. None of the columns in the table can be NULL.

QUESTION: - In a database create the following tables with suitable constraints :


ANSWERS: -
CREATE TABLE Vehicle(RegNo CHAR(10) PRIMARY KEY NOT NULL, RegDate DATE,Owner
VARCHAR(30),
Address VARCHAR(50));
CREATE TABLE CHALLAN(Challan_No INT(11) PRIMARY KEY NOT NULL DEFAULT ‘0’, Ch_Date
DATE, RegNo CHAR(10), Offence INT(3));
CREATE TABLE OFFENCE(Offence_Code INT(3) PRIMARY KEY NOT NULL DEFAULT ‘0’, Off_desc
VARCHAR(30), Challan_Amt INT(4));

a) Based on these tables write SQL statements for the following queries:
i. Display the dates of first registration and last registration from the table Vehicle.
A. SELECT MIN(RegDate) AS “First registration”, MAX(RegDate) AS “Last registration” FROM
VEHICLE;
ii. Display the number of challans issued on each date.
A. SELECT COUNT(*) AS “Number of challans”,Ch_Date FROM CHALLAN GROUP BY Ch_Date;
iii. Display the total number of challans issued for each offence.
A. SELECT COUNT(*) AS “Number of challans”, Offence FROM CHALLAN GROUP BY Offence;
iv. Display the total number of vehicles for which the 3rd and 4th characters of RegNo are “6C”.
A. SELECT COUNT(RegNo) WHERE RegNo LIKE “__6C%” AND RegNo LIKE “___6C%”;
v. Display the total value of challans issued for which the Off_Desc is “Driving without License”.
A. SELECT COUNT(Challan_No) FROM CHALLAN WHERE Off_Desc=“Driving without License”;
vi. Display details of the challans issued on “2010-04-03” along with Off_Desc for each challan.
A. SELECT Challan_No, Ch_Date, RegNo, Offence, Off_desc FROM CHALLAN, OFFENCE WHERE
Ch_Date=“2010-04-03”;
vii. Display the RegNo of all vehicles which have been challaned more than once.
A. SELECT RegNo FROM Vehicle WHERE Challan_No>1;
viii. Display details of each challan alongwith vehicle details, Off_desc, and Challan_Amt.
A. SELECT Challan_No, Ch_Date, RegNo, Offence, RegDate.VEHICLE, Owner.VEHICLE,
Address.VEHICLE”, Off_desc.OFFENCE, Challan_Amt.OFFENCE” FROM CHALLAN, VEHICLE;

b) Identify the Foreign Keys (if any) of these tables. Justify your choices.
A. RegNo is the foreign key for the tables as it can be used to link each other.

c) Should any of these tables have some more column(s)? Think, discuss in peer groups, and discuss
with your teacher.
A. No, there is no need of more column(s) in any of the tables.
ADVANCE RDBMS CONEPT
QUESTION: - Perform the following tasks:
 Start MySQL session.
 Create a table named Student with columns RollNumber, Name and Marks.
 Start a transaction and insert two rows to the Student table.
 Verify the inserts by SELECT statement.
 Commit the changes.
 Start another transaction.
 Delete a row that was recently inserted.
 Verify that the row has been deleted.
 Rollback the changes.
 Verify that the delete has been cancelled.
ANSWERS: -
QUESTION: - Write the output that will be displayed by each SELECT statement as the SQL
statements given below are executed:
 SELECT * FROM ITEM;
 SET AUTOCOMMIT = 0;
 INSERT INTO ITEM VALUES(103,'COFFEE TABLE',340);
 SELECT * FROM ITEM;
 ROLLBACK;
 SELECT * FROM ITEM;
 START TRANSACTION;
 UPDATE ITEM SET IPRICE = IPRICE +200;
 SAVEPOINT S1;
 UPDATE ITEM SET IPRICE = IPRICE +400;
 SELECT * FROM ITEM;
 ROLLBACK TO S1;
 SELECT * FROM ITEM;

ANSWERS: -

Das könnte Ihnen auch gefallen