CBSE IP Practical File 2015 (Java and MySQL)
CBSE IP Practical File 2015 (Java and MySQL)
PROGRAM
ONE-----------------------------------------------------------------------Aim : To make a program which appends the information given.
Design :
PROGRAM
TWO----------------------------------------------------------------------Aim : To make a calculator.
Design :
Code :
3
For divide button :
Double n1,n2,n3;
n1 = Double.parseDouble(t1.getText());
n2 = Double.parseDouble(t2.getText());
n3 = n1/n2;
l1.setText(""+n3);
For clear button :
t1.setText("");
t2.setText("");
l1.setText("");
Output :
PROGRAM
THREE--------------------------------------------------------------------Aim : To make a program that counts integers between two given integers.
Design :
Code :
Output :
PROGRAM
FOUR---------------------------------------------------------------------Aim : To create a LCM and HCF calculator.
Design :
6
int a=Integer.parseInt(one.getText());
int b=Integer.parseInt(two.getText());
int w, x=a, y=b, z;
while (y!=0)
{w=y;
y=x%w;
x=w;}
z=(a*b)/x;
disp.setText("The HCF is "+x+"\nThe LCM is "+z);}
Output :
PROGRAM
FIVE-----------------------------------------------------------------------Aim : To create percentage calculator.
Design :
8
O=(P+C+M+E+I)/5;
String G=null;
if (O>=90) { G="A+";}
else if(O>= 80 && O<90) {
G = "A-";}
else if(O>= 70 && O<80) {
G = "B+";}
else if(O>= 60 && O<70) {
G = "B-";}
else if(O>= 50 && O<60) {
G = "C+";}
else if(O>= 40 && O<50) {
G = "C-";}
else {
G = "You got F";}
s.s
For Clear Button :
s.setText(null);
For Exit Button :
System.exit(0);
Output :
PROGRAM
10
11
PROGRAM
SEVEN--------------------------------------------------------------------Aim : Design an application in which user enters his chat ID and City
Design :
12
Output :
13
PROGRAM
EIGHT--------------------------------------------------------------------Aim : Practical to illustrate the usage and functionality of String methods.
////////////////////////////////////////////////Arnav Solanki /////// XII A//////Roll No. 5
14
Design :
15
{
outTA.append(\n\nCOMPARE STRINGS\n);
outTA.append(\n----------\n);
outTA.append(Compare + name1 +and + name2 +=
namel.compareTo(name2));
outTA .append( /nCompare+ name2 + and+ name1 +
name2.compareTo(name1));
outTA .append( /nCompare+ name2 + and+ name1 +
name2.compareTo(name2));
Output :
PROGRAM
NINE----------------------------------------------------------------------////////////////////////////////////////////////Arnav Solanki /////// XII A//////Roll No. 5
16
Aim : To design a simple purpose dialog through the application.
Design :
MsgDialog2.setVisible(true);
For OK Button:
System.exit(0);
Output :
17
18
PROGRAM
TEN------------------------------------------------------------------------Aim : To design that decides the eligibility of the user as per his age.
Design :
19
Output :
20
PROGRAM
ELEVEN-------------------------------------------------------------------Aim : To create a table that can receive input of the user and also display total count
of records.
Design :
21
cnt = 1;
A= tbl.getValueAt(i,2);}}
msg = msg+" Class "+tbl.getValueAt(i-1,2)+" has "+cnt+" students.\n";
JOptionPane.showMessageDialog(null,msg);
For Exit Button:
System.exit(0);}
Output :
22
PROGRAM
TWELVE------------------------------------------------------------------Aim : To create a table that can receive input of the user and manage an address
book.
Design :
23
For Statistics Button :
int r = tbl.getRowCount();
JOptionPane.showMessageDialog(null,"Total Records in the address in the
book:"+r);
For Exit Button:
System.exit(0);}
For Search Button:
int c = Integer.parseInt(t5.getText());
int r = Integer.parseInt(t6.getText());
Object A = t6.getText();
c = c-1;
int i;
for(i=0;i<r; ++i)
{Object f = tbl.getValueAt(i,c);
if(f.equals(A))
{JOptionPane.showMessageDialog(rootPane,"Exists in Record");}
else {JOptionPane.showMessageDialog(rootPane, "Record with this value doesn't
exist");}}
Output :
24
PROGRAM
THIRTEEN----------------------------------------------------------------Aim : To create a GUI component that updates and deletes records on a database.
Design :
Code :
public class Connectivity extends javax.swing.JFrame {
Connection con= null;
Statement stmt = null;
ResultSet rs = null;}
For Load Button:
private void loadBtnActionPerformed(java.awt.event.ActionEvent evt)
try{Class.forName(java.sql.Driver);
con=DriverManager.getConnection(jdbc:mysql://localhost/test,root,friends);
stmt = con.createStatement();
String query =SELECT * FROM dept WHERE deptno=+deptnoTF.getText()+;;
rs = stmt.executeQuery(query);
i f ( r s . n ex t ( ) ) {
String dno = .getString(deptno};
String dname =rs.getString(deptno);
String lc = rs.getString(loc );
dnameTF.setText(dname);
locTF.setText(lc);
updBtn.setEnabled(true); delBtn.setEnabled(true); locTF.setEnabled(true);}
else{JOptionPane.showMessageDialog(null,No such record Found):}}
Catch(Exception e){JOptionPane.showMessageDialog(null,Error in
Connectivity);
////////////////////////////////////////////////Arnav Solanki /////// XII A//////Roll No. 5
25
For Update Button:
private void updBtnActionPerformed(java.awt.event.ActionEvent evt) int ans
= JOptionPane.showConfirmDialog(null,Surely wanna update the records?);
if (ans == JOptionPane.YES_OPTION) {
try{stmt = con.createStatement();
26
stmt=con.createStatement();
String query =DELETE FROM dept WHERE
deptno=+deptnoTF.getText0+;;
stmt.executeUpdate(query);
JOptionPane.showMessagebialog(null,Record successfully deleted.);}
catch (Exception e ){
JOptionPane.showMessageDialog(null,Error in deletion!);}
deptnoTF.setText();
dnameTF.setText();
locTF.setText();
updBtn.setEnabled(false);
del Btn.setEnab led(false);}}
Output :
27
PROGRAM
FOURTEEN--------------------------------------------------------------Aim : To create GUI application that obtains search criteria from user and retrieve
data from database.
Design :
28
Class.forName(java.sql.Driver);
Connection con=
DriverManager.getConnection(jdbc:mysql://localhost/test,root,friends);
Statement stmt = con.createStatement();
String sfId = (String)srchFldCBX.getSelectedItem();
String op = (String)opCBX.getSelectedItem();
String crit = criteriaTF.getText();
String query =SELECT empno,ename,job,hiredate,sal,deptno FROM empl WHERE+
sfld + + op + + crit +;;
ResultSet rs = stmt.executeQuery(query); while(rs.next()){
model.addRow(new Object[] {rs.getInt(1), rs.getString(2), rs.getString(3),
rs.getDate(4), rs.getFloat(5), rs.getInt(6)});}
rs.close();
stmt.close();
con.close();}
catch(Exception e ){
JOptionPane.showMessagebialog(null ,ERROR IN CONNECTIVITY);}
Output :
29
PROGRAM
FIFTEEN------------------------------------------------------------------Aim : Consider the table empl given below and run the following Queries.
Queries:
1. List the details of those employees whose annual salary is between
25000 and 40000.
SELECT * FROM empl where sal BETWEEN 2500 AND 4000;
30
3. Display Name, Job and Salary of employees who do not have a manager.
SELECT ename, job, sal FROM empl WHERE mgr IS NULL;
31
PROGRAM
SIXTEEN------------------------------------------------------------------Aim : Consider the table EMPLOYEE given below and run the following Queries.
Queries:
1. For record with ID=4 update record with last Name, User ID and Salary.
UPDATE employe SET Last_Name=SAHUKAR,User_ID=skar,Salary=9000
WHERE ID=4;
32
4. Delete the employee record having first name as SIDDHARTH.
DELETE FROM employe WHERE First_Name=SIDDHARTH;
5. Modify the salary and increases it by 1000, for all who get salary less
than 5000.
UPDATE employe SET Salary =Salary+1000 WHERE Salary<5000;
33
PROGRAM
SEVENTEEN-------------------------------------------------------------Aim : Consider the table STUDENT given below and run the following Queries.
Queries:
1. Display Name, Sex, Percentage of the Students.
SELECT name, sex, aggregate/5 AS Percentage FROM student;
34
3. Display name, age and marks of students whose age is greater than or
equal to 14 from student.
SELECT
5. Alias any column name and use that name in another statement.
SELECT name, aggregate/5 Percentage Marks FROM student ORDER BY
Percentage NAME;
35
PROGRAM
EIGHTEEN----------------------------------------------------------------Aim : Join two Tables.
Queries:
1. Write a query to join two tables empl and dept on the basis of field
deptno.
SELECT * FROM empl,dept WHERE empl.deptno=dept.deptno GROUP BY
empno;
36
37
PROGRAM
NINETEEN---------------------------------------------------------------Aim : Join two Tables.
Queries:
1. Write commands to create the above tables with constraints. Delete on
a primary key should be cascaded to its foreign key.
CREATE TABLE employe (empno INTEGER NOT NULL, salary FLOAT, PRIMARY KEY
(empno)) ENGINE=innodb;
CREATE TABLE employer (ID INTEGER NOT NULL, employee_no INTEGER,
FOREIGN KEY(employee_no) REFERNCES employer(empno) ON DELETE
CASCADE) ENGINE=innodb;
2. Write a query to create two tables Tt1 and Tt2, such that a column of
the table Tt1 is the foreign key referring to table Tt2 (constraint name
fk1).
CREATE TABLE Tt1 (A INTEGER NOT NULL PRIMARY KEY, B INTEGER NOT NULL);
CREATE TABLE Tt2 (C INTEGER NOT NULL PRIMARY KEY, D INTEGER NOT NULL);
ALTER TABLE Tt1 ADD CONSTRAINT fk1 FOREIGN KEY (B) REFERENCES Tt2(C)
ON DELETE CASCADE;
3. Write a query to delete primary key from table namely Tt1.
////////////////////////////////////////////////Arnav Solanki /////// XII A//////Roll No. 5
38
ALTER TABLE Tt1 DROP PRIMARY KEY;
4. Write a query to add primary key to column ename of table empl.
ALTER TABLE empl ADD PRIMARY KEY (ename);
5. In table empl, add a column named THRIFTPALN of datatype NUMBER
with a maximum of 7 digits and two decimal places anda column
named LOANCODE of datatype CHAR with a size of one and integrity
constraint that checks that loan code should be one of these: E, C, H, P.
ALTER TABLE empl ADD (Thriftplan NUMBER(7,2), Loancode CHAR(1) CHECK
(Loancode IN(E,C,H,P)));