You are on page 1of 15

ADVANCE

CLIENT-
SERVER
TECHNOLOGY

LAB FILE

Submitted By:
Sameer Mathur
IT-2149-2K14
INDEX
S.No. Program Name Signature

1. Write a program to check whether a number is even or odd

2. Write a program to swap two numbers

3. Write a program to calculate area of a rectangle

4. Write a program to implement function overloading

5. Write a program to implement constructor overloading

6. Write a program to implement this keyword

7. Write a program to implement static keyword

8. Write a program to implement method overriding

9. Write a program to implement Exception handling

10. Write a program to implement Multithreading

11. Write a program to prompt the user to enter the current day and display
whether it is a weekend or a weekday

12. Write a program to ask a question from the user and accept an answer. The
user is given three chances. If the user fails three times, an alert displaying
wrong answer is shown on the screen

13. Write a program to count the number of objects on the screen

14. Write a program to check whether text boxes in the form are empty. If it is
so, display an alert showing their name.

15. Write a program to perform the appropriate mathematical operation


according to the radio button selected.

16. Write a program to read the current date and display in the given format.

17. Write a program to create a multiple choice list in JavaScript and display the
item(s) selected in the text area on the click of the button

18. Write a program to execute select query using JDBC

19. Write a program to execute DML commands using JDBC


Q11

<!DOCTYPE html>

<html>

<script>

function myfunc()

var day = prompt("Please enter the current day");

day = day.toLowerCase();

if(day == "sunday" || day == "saturday")

document.getElementById("daydisplay").innerHTML = "Weekend";

else

document.getElementById("daydisplay").innerHTML = "Weekday";

</script>

<body onload=myfunc()>

<p id="daydisplay"></p>

</body>

</html>
Q12

<!DOCTYPE html>

<html>

<script>

function ques()

var flag = 0;

for(i=0;i<3;i++)

var ans = prompt("What is 4+5 ?");

if(ans == 9)

flag = 1;

break;

if(flag==0)

alert("Wrong answer");

</script>

<body onload=ques()>

</body>

</html>
Q13

<!DOCTYPE html>

<html>

<script>

function count()

alert("No. of objects on screen are "+form1.getElementsByTagName('input').length);

</script>

<body onload=count()>

<form id = "form1">

<input type="text" id="tb1">

<input type="text" id="tb2">

<input type="radio" id="radio1">

<input type="button" id="button1">

<input type="checkbox" id="cb1">

</form>

</body>

</html>
Q14
<!DOCTYPE html>

<html>

<script>

function check()

var empty="";

var inputs = form1.getElementsByTagName('input');

for(i=0;i<inputs.length;i++)

if(inputs[i].getAttribute('type')=='text')

if(inputs[i].value=="")

empty = empty + inputs[i].name + ", ";

alert(empty + "are empty");

</script>

<body>

<form id = "form1">

<input type="text" name="Text Box 1" id="tb1"><br><br>

<input type="text" name="Text Box 2" id="tb2"><br><br>

<input type="text" name="Text Box 3" id="tb3"><br><br>

<input type="text" name="Text Box 4" id="tb4"><br><br>

<button onclick="check()">Click to check!</button>

</form>

</body>

</html>
Q15

<!DOCTYPE html>

<html>

<script>

function calc()

var opn;

var n1 = parseFloat(document.getElementById("tb1").value);

var n2 = parseFloat(document.getElementById("tb2").value);

var n3 = document.getElementById("tb3");

var inputs = form1.getElementsByTagName('input');

for(i=0;i<inputs.length;i++)

if(inputs[i].getAttribute('type')=='radio')

if(inputs[i].checked==true)

opn=inputs[i].value;

if(opn=="add")

n3.value = n1 + n2;

else if(opn=="subtract")

n3.value = n1 - n2;

else if(opn=="multiply")

n3.value = n1 * n2;

else if(opn=="divide")

n3.value = n1 / n2;

}
</script>

<body>

<form id = "form1">

Value1 = <input type="text" id="tb1" value=""> <br><br>

Value2 = <input type="text" id="tb2" value=""> <br><br>

<input type="radio" name="operation" value="add"> Add <br>

<input type="radio" name="operation" value="subtract"> Subtract<br>

<input type="radio" name="operation" value="multiply"> Multiply<br>

<input type="radio" name="operation" value="divide"> Divide<br><br>

Result = <input type="text" id="tb3" value=""><br><br>

<button type="button" onclick="calc()">Calculate!</button>

</form>

</body>

</html>
Program 16.

Write a program to read the current date and display in the given format.

<!DOCTYPE html>

<html>

<script type="text/JavaScript">

function getDate(){

var today=new Date();

var dd=today.getDate();

var mm=today.getMonth()+1;

var yyyy=today.getFullYear();

if(dd<10){

dd='0'+dd;

if(mm<10){

mm='0'+mm;

today=mm+'-'+dd+'-'+yyyy;

document.write(today);

document.write("<br>");

today = mm+'/'+dd+'/'+yyyy;

document.write(today);

document.write("<br>");

today = dd+'-'+mm+'-'+yyyy;

document.write(today);

document.write("<br>");
today = dd+'/'+mm+'/'+yyyy;

document.write(today);

</script>

<body>

<button onclick="return getDate()">The time is?</button>

</body>

</html>
Program 17.

Write a program to create a multiple choice list in JavaScript and display the
item(s) selected in the text area on the click of the button

<html>

<head>

<script type="text/javascript">

function getSelectValues(select) {

var result = [];

var options = select && select.options;

var opt;

for (var i=0, iLen=options.length; i<iLen; i++) {

opt = options[i];

if (opt.selected) {

result.push(opt.value || opt.text);

return result;

</script>

</head>

<body>

<h3>Select the Multiple Operating Systems</h3>

<select multiple style="width:200px; height:100px">


<option value="Ubuntu">Ubuntu

<option value="Windows">Windows

<option value="MacOS">MacOS

<option value="Linux Mint">Linux Mint

<option value="Debian">Debian

</select>

<br><br>

<button onclick="

var el = document.getElementsByTagName('select')[0];

alert(getSelectValues(el));

">Show selected values</button>

</body>

</html>
Program 18.

Write a program to execute select query using JDBC

import java.sql.*;

class Query1 {

public static void main (String[] args) {


try {
String url = "jdbc:mysql://200.210.220.1:1114/Demo";
Connection conn = DriverManager.getConnection(url,"","");
Statement stmt = conn.createStatement();
ResultSet rs;

rs = stmt.executeQuery("SELECT Lname FROM Customers WHERE Snum = 2001");


while ( rs.next() ) {
String lastName = rs.getString("Lname");
System.out.println(lastName);
}
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
Program 19.

Write a program to execute DML commands using JDBC

import java.sql.*;

public class InsertExample {


public static void main(String[] args)
throws SQLException {
int ret_code;
Connection conn = null;
try {
int i_empno[] = {1001, 1002, 7788};
String i_ename[] = {"JOHN","DAVID","ORATEST"};
String i_job[] = {"MANAGER","ANALYST","CLERK"};
int i_mgr[] = {7839, 1001, 1002};
String i_hiredate = "01-JAN-01";
float i_sal[] = {10000,6000, 4000};
float i_comm[] = {2000,1000,500};
int i_deptno = 10;
//Load and register Oracle driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//Establish a connection

conn = DriverManager.getConnection("jdbc:oracle:thin:@training:1521:
Oracle", "oratest", "oratest");

String sql1 = "SELECT empno FROM emp WHERE empno = ?" ;


String sql2 = "INSERT INTO emp VALUES (?,?,?,?,?,?,?,?)";

PreparedStatement pstmt1 = conn.prepareStatement(sql1);


PreparedStatement pstmt2 = conn.prepareStatement(sql2);
for (int idx=0;idx<3;idx++)
{
pstmt1.setInt(1, i_empno[idx]);
ResultSet rset = pstmt1.executeQuery();
if (rset.next()) {
System.out.println("The employee "
+i_empno[idx]+" already exists.");
rset.close();
}
else
{
pstmt2.setInt(1, i_empno[idx]);
pstmt2.setString(2, i_ename[idx]);
pstmt2.setString(3, i_job[idx]);
pstmt2.setInt(4, i_mgr[idx]);
pstmt2.setString(5, i_hiredate);
pstmt2.setFloat(6, i_sal[idx]);
pstmt2.setFloat(7, i_comm[idx]);
pstmt2.setInt(8, i_deptno);
pstmt2.executeUpdate(); }
} // End of for loop
pstmt1.close();
pstmt2.close();
conn.close();
} catch (SQLException e) {ret_code = e.getErrorCode();
System.err.println(ret_code + e.getMessage()); conn.close();}
}
}

You might also like