Professional Documents
Culture Documents
Aayushi Maurya 02 Ajp Exp 14 - 24
Aayushi Maurya 02 Ajp Exp 14 - 24
X. Program Code:
1. Execute the following code and write the output
import java.io.*;
import java.net.*;
public class InetDemo
{
public static void main(String[] args)
{
try
{
InetAddress ip=InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e){System.out.println(e);}
}
}
ANS-
1|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
2|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. Exercise
1. Develop a program using InetAddress class to retrieve IP address of
computer when hostname is entered by the user.
ANS-
3|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
4|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
5|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. Exercise
1. Write a program using URL class to retrieve the host, protocol, port and
file of URL http://www.msbte.org.in
ANS-
6|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
2. Write a program using URL and URLConnection class to retrieve the date,
content type, content length information of any entered URL
ANS-
7|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
Practical No. 18: Write a program to insert and retrieve the data
from database using JDBC
X. Program Code-
1. Write a Program to create a Student Table in database and insert a record in a
student table.
ANS-
8|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
9|P age
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. EXERCISE-
1. Develop a program to create employee table in database having two columns
“emp_id” and “emp_name”.
Ans-
10 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
2. Develop a program to display the name and roll_no of students from “student
table” having percentage > 70.
ANS-
11 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
12 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
13 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
2. Write the output of following JDBC code. Use Mysql server 5.5 as database
14 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
server
ANS-
15 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
1) public boolean next(): is used to move the cursor to the one row next from
the current position.
2) public boolean previous(): is used to move the cursor to the one row previous
from the current position.
3) public boolean first(): is used to move the cursor to the first row in result set
object.
4) public boolean last(): is used to move the cursor to the last row in result set
object.
5) public boolean absolute(int is used to move the cursor to the specified row
row): number in the ResultSet object.
6) public boolean relative(int is used to move the cursor to the relative row number
row): in the ResultSet object, it may be positive or negative.
7) public int getInt(int is used to return the data of specified column index of
columnIndex): the current row as int.
16 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
8) public int getInt(String is used to return the data of specified column name of
columnName): the current row as int.
9) public String getString(int is used to return the data of specified column index of
columnIndex): the current row as String.
10) public String getString(String is used to return the data of specified column name of
columnName): the current row as String.
3. Explain Types of ResultSet
ANS-
There are two types of result sets namely, forward only and, bidirectional.
Forward only ResultSet: The ResultSet object whose cursor moves only in one
direction is known as forward only ResultSet. By default, JDBC result sets are
forward-only result sets
17 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. Exercise
1. Develop JDBC program to retrieve data using ResultSet
ANS-
18 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
19 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
20 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
21 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
22 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
ANS-
23 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
24 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
Create
Drop
DDL Alter
Rename
Truncate
Select
Insert
DML
Update
Delete
Grant
DCL Revoke
25 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. EXERCISE-
1. Develop a program to delete all record for a product whose "price is greater
than 500" and Id is "P1234".
ANS-
26 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
27 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
ANS-
28 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
29 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
2. Write the output of following code considering below HTML is front end and
servlet as back end
ANS-
30 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
31 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
DoGet is faster if we set the response DoPost is slower compared to doGet since
content length since the same doPost does not write the content length
connection is used. Thus increasing the
performance
DoGet should be idempotent. i.e. doget This method does not need to be idempotent.
should be able to be repeated safely Operations requested through POST can
many times have side effects for which the user can be
held accountable, for example, updating
stored data or buying items online.
DoGet should be safe without any side This method does not need to be either safe
effects for which user is held
responsible
32 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. Exercise
1. Develop servlet program to retrieve data from List and Radio Button using
HTML forms.
ANS-
33 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
34 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
ANS-
35 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
36 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
37 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
38 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
39 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
40 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
41 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
42 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
43 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
44 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
XIII. Exercise
ANS-
45 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
46 | P a g e
AAYUSHI MAURYA-02
Advanced Java Programming (AJP)
47 | P a g e