• No results found

CBSE IP Practical file 2015 (Java and MySQL)

N/A
N/A
Protected

Academic year: 2021

Share "CBSE IP Practical file 2015 (Java and MySQL)"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

Code : For Submit Button – String a = t1.getText(); String b = t9.getText(); String c = t3.getText(); String d = t4.getText(); String e = t5.getText(); String f = t6.getText(); ta.append("Name : "+a+"\n"+"House no :"+b+"\n"+"Building :"+c+"\n"+"Street :"+d+"\n" +"City :"+e+"\n"+"State :"+f+"\n");

(2)

Design :

Code :

For add button :

Double n1,n2,n3; n1 = Double.parseDouble(t1.getText()); n2 = Double.parseDouble(t2.getText()); n3 = n1+n2; l1.setText(""+n3);

For subtract button :

Double n1,n2,n3;

n1 = Double.parseDouble(t1.getText()); n2 = Double.parseDouble(t2.getText()); n3 = n1-n2; l1.setText(""+n3);

For multiply button :

Double n1,n2,n3; n1 = Double.parseDouble(t1.getText()); n2 = Double.parseDouble(t2.getText()); n3 = n1*n2; l1.setText(""+n3);

(3)
(4)

Code :

For Count button : double i =Double.parseDouble(t1.getText()); double j =Double.parseDouble(t2.getText()); if(j<i) {for(;j<=i;j++){ ta.append(" "+j);} } else {for(;i<=j;i++){ ta.append(" "+i); }} Output :

(5)

PROGRAM

FOUR---

---Aim : To create a LCM and HCF calculator. Design :

Code : For Calculate Button :

(6)
(7)

PROGRAM

FIVE-

---Aim : To create percentage calculator. Design :

Code : For Calculate Button :

private void CalculateActionPerformed(java.awt.event.ActionEvent evt) { int P= Integer.parseInt(p.getText()); int C= Integer.parseInt(c.getText()); int M= Integer.parseInt(m.getText()); int E= Integer.parseInt(e.getText()); int I= Integer.parseInt(i.getText()); double O;

(8)

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);

(9)

PROGRAM

SIX---

---Aim : To create a registration for placements of job seekers. Design :

(10)

Code : For Submit Button if(pgtcb.isSelected()==true) { gradcb.setSelected(true); intercb.setSelected(true); } if(gradcb.isSelected()==true) { intercb.setSelected(true); } String str = null; if(malerb.isSelected()) { str = "Hello Mr. "+ name.getText()+" you are registered";} else if(femalerb.isSelected()) { str = "Hello Ms. "+ name.getText()+" you are registered";} JOptionPane.showMessageDialog(null,str);

For Clear Button :

gradcb.setSelected(false); intercb.setSelected(false); pgtcb.setSelected(false); name.setText(null); malerb.setSelected(false); femalerb.setSelected(false);

For Close Button :

System.exit(0);

(11)

PROGRAM

SEVEN---

---Aim : Design an application in which user enters his chat ID and City Design :

(12)

Code : For Login Button:

String name=t1.getText(); String city=(String)c1.getSelectedItem(); l1.setText("<html>Hi "+ name +", Welcome to W3schools.net<br>How is The Weather in "+city);

(13)

PROGRAM

EIGHT---

(14)

Code : For Submit Button:

private void jButtonlActionPerformed(java.awtevent.ActionEvent evt){ String name1 = String(); name1 = .getText(); String name2 = String(); name2 = .getText(); String name3 = String(); name3 = .getText(); lengthOfString(name1); characterAtIndex(namel); compareString(namel , name2); concatinationl(namel , name2); concatination2(namel , name2); occurenceOfN(name3); subString(name3); replaceCharacter(name3); caseConversion(namel); } public void length0f5tring(String name) outTA.append( “LENGTH OF STRING”); outTA.append( “\n---\n”); outTA.append("Lenght Of String" + name + " is " + name.length( )); } public void characterAtIndex(String name) { outTA.append(“\n\nCHARACTER AT INDEX N\n” ); outTA.append(“\n---\n”) outTA.append(“At O the character is” + name.charAt(0)); outTA.append(“\n At 3 the character is” + name.charAt(3)); } public void comparestrings(String namel , String name2)

(15)

PROGRAM

NINE

(16)

---Code : For Show Button:

MsgDialog2.setVisible(true);

For OK Button:

System.exit(0);

(17)
(18)

Code : For Check Eligibility Button:

String a = JOptionPane.showInputDialog("Enter Age"); try{ int age= Integer.parseInt(a); if(age>=13 && age<=20) JOptionPane.showMessageDialog(null,"Is Eligible"); else JOptionPane.showMessageDialog(null,"Is not Eligible");} catch(NumberFormatException e){ JOptionPane.showMessageDialog(null,"Enter age as Numeric Value"); }

(19)
(20)

Code : For Add row Button:

Object []x = {t1.getText(),t2.getText(),t3.getText(),t4.getText(),}; DefaultTableModel Tbl = (DefaultTableModel)tbl.getModel(); Tbl.addRow(x);

For Display Count Button:

JOptionPane.showMessageDialog(null, tbl.getRowCount());

For Classwise Count Button :

int a = tbl.getRowCount(); Object A = tbl.getValueAt(0,2); Object val = new Object(); int cnt = 1; String msg = new String(); int i; for(i=1; i<a; ++i) {val = tbl.getValueAt(i,2); if(val.equals(A)) {cnt++;} else {msg = msg+"Class "+tbl.getValueAt(i-1,2)+" has "+cnt+" students.\n";

(21)
(22)

Code : For Add Record Button:

Object []x = {t1.getText(),t2.getText(),t3.getText(),t4.getText()}; DefaultTableModel a = (DefaultTableModel)tbl.getModel(); a.addRow(x); int sn = Integer.parseInt(t1.getText()); t1.setText(""+(++sn)); t2.setText(""); t3.setText(""); t4.setText("");

For Clear Record Button:

t2.setText(""); t3.setText(""); t4.setText("");

(23)

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");}}

(24)

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); if (rs.next()){ 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”);

(25)

try{stmt = con.createStatement();

String query =”UPDATE dept SET dname=” ”+ dnameTF.getText()+”;” “loc=” “+locTF.getText()+” WHERE deptno =” ”+deptnoTF.getText()+”;” stmt.executeUpdate(query); JOptionPane.showMessageDialog(null,”Record successfully updated”);} catch (Exception e ){ JOptionPane.showMessageDialog(null,”Error in table updation!”);} deptnoTF.setText(“”); dnameTF.setText(“”); IocTF.setText(“”); updBtn.setEnabled(false); delBtn.setEnabled(false);}}

For Delete Button:

private void delBtnActionPerformed(java.awt.event.ActionEvent evt) { int res = JOptionPane.showConfirmDialog(null,”Surely wanna delete the records?”); if ( res == JOptionPane.YES_OPTION){

(26)

JOptionPane.showMessageDialog(null,”Error in deletion!”);} deptnoTF.setText(“”);

dnameTF.setText(“”);

locTF.setText(“”);

updBtn.setEnabled(false);

del Btn.setEnab led(false);}}

(27)

Code : For Empty Table Button:

private void emptyBtnActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel) empTbl.getModel();

int rows = model.getRowCount(); if(rows>0) for(int i =0 ; i<rows; i++) { model.removeRow(0);}}

For Search Button:

private void searchBtnActionPerformed(java.awt.event.ActionEvent evt){ emptyBtn.doClick(); DefaultTableModel model = (DefaultTableModel)empTbl.getModel(); try{

(28)

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”);}

(29)

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;

2. Display the name of employees whose name contains ‘A’ as the 4th

alphabet.

(30)

SELECT ename, sal, sal+comm FROM empl;

5. Display details of employees who earn more commission than their salaries.

(31)

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;

2. Modify the last name of employees to Gautam where salary<5000.

UPDATE employe SET Last_Name=’Gautam’ WHERE Salary<5000;

3. Add column Email of data type VARCHAR to the table.

(32)

5. Modify the salary and increases it by 1000, for all who get salary less than 5000.

(33)

Queries:

1. Display Name, Sex, Percentage of the Students.

SELECT name, sex, aggregate/5 AS Percentage FROM student;

2. Display in the following format:

<Student name> obtained <aggregate> marks and has <aggregate/5> %

SELECT name,”obtained”,aggregate,”marks and has”,aggregate/5,”%” FROM student;

(34)

3. Display name, age and marks of students whose age is greater than or equal to 14 from student.

SELECT name,age,aggregate FROM student WHERE AGE>=14;

4. Display name, age, aggregate of student whose aggregate is between 300 and 400. Order the query in descending order of name.

SELECT name, age, aggregate FROM student WHERE aggregate BETWEEN 300 AND 400 ORDER BY name DESC;

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)

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;

2. Remove the duplicate deptno.

(36)

3. Display details like department no, department name, employee number, employee name, job and salary. And order the rows of by employee number with number.

SELECT empl.deptno, dname, empno, ename, job, sal FROM empl, dept WHERE empl.deptno=dept.deptno GROUP BY empno ORDER BY empl.deptno, empno;

4. Calculate average salary of all employees listed in table empl.

SELECT AVG(sal) “Average” FROM empl;

5. Display the joining date of senior most employee.

(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;

(38)

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’)));

References

Related documents

Today, Sunset Grill is Ontario’s favourite breakfast restaurant with 50 locations and growing.. Over the next 12 month span, Sunset Grill is opening at least 20 new franchised

After peak area integration, the pipeline clusters peaks between samples based on their mass spectral similarity and retention time behaviour in both dimensions to form peak

estoppel. “The Debtor’s reliance on her attorney. relieves her neither of her affirmative duty to disclose nor of the diligence required to ensure the Court that her

In fact, BG prevalence varies widely across markets, and recent research shows that group affiliation remains common even in some highly-developed economies

Information technologies that contribute to knowledge management solutions, such as enterprise portals, improve the enterprise’s business intelligence and its

“….Nadee… now you are a brown belt holder… you must never use your ability to hurt people… always use it for self defence and to protect the others…..” “…Nadee…

Based on the problem descriptions and discussions of the support structure of the decision to AHP (Analytical Hierarchy Process) medium or small business

Purdue University, Krannert School of Management, Strategic Management Seminar (2005) SMU, Cox School of Business, Strategy and Entrepreneurship Seminar (2004). Tilburg