Ajp QB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

1 In following Java program fill statement showing ***.

Select any one option fro given options


import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}

1. new Cookie("MyCookie", data); 2. new Cookie("MyCookie", data1);

3. Cookie("MyCookie", data2); 4. new Cookie("MyCookie", data2);

1
2. What we should write at the place of____________ to get the proper output.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class password extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletExc
{
response.setContentType("text/html");
PrintWriter out = ________________
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
String a= request.getParameter("t1");
String b= request.getParameter("t2");
int a1 =a.length();
int b1= b.length();
if(b.length()<=6)
{
out.println("<h3> Welcome To Home Page<h3>");
}
else
{
out.println("<h3>Password Should not more than 6 Character<h3>");
}
out.println("</body>");
out.println("</html>");
}
}

1. response.getWriter(); 2. request.getWriter();

3. res.getWriter(); 4. response.getwriter();

3. What does the following code do?


while(rs.next())
{
String n=rs.getString("name");
System.out.println("name:"+n);
String n1=rs.getString("rollnumber");
System.out.println("rollnumber:"+n1);
}

1. create connection 2. Display Record

2
3. prepare the statement object 4. none of the above

4. Which Statement is given the error in the following code

import java.sql.*;
class dataI
{
public static void main(String a[])
{
try
{
Driver d= new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
Connection con =DriverManager.getConnection("Jdbc:Odbc:xxx");
Statement s=con.createStatement();
s.executeUpdate("Insert into Table1 values('hhh',12)");
if(n==1)
{
System.out.println("Record inserted ");
con.close();
}
}
catch(Exception e)
{
System.out.println("not Inserted"+e);
}}}

1. Statement Object creation 2. Sql Query Statement and variable


statement
3. Connection Statement 4. Table Statement

5. Identify the correct sequence for querying the database There are seven standard steps in querying data

1. • Load the JDBC driver. 2 • Load the JDBC driver.


• Define the connection URL. • Define the connection URL.
• Establish the connection. • Establish the connection.
• Execute a query or update. • Create a statement object.
• Create a statement object. • Execute a query or update.
• Process the results. • Process the results.
• Close the connection. • Close the connection.

3 • Load the JDBC driver. 4 • Load the JDBC driver.


• Establish the connection. • Define the connection URL.
• Define the connection URL. • Establish the connection.
3
• Create a statement object. • Process the results.
• Execute a query or update. • Create a statement object.
• Process the results. • Execute a query or update.
• Close the connection. • Close the connection.

6. What will be the output of the following program


import java.net.*;
class networking {
public static void main(String[] args) throws UnknownHostException {
InetAddress obj1 = InetAddress.getByName("google.com");
InetAddress obj2 = InetAddress.getByName("google.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
}
}

1. true 2. false

3. 1 4. 0

7. which are the syntax of close() method in connection interface method

1. connection.close(); 2. Connection.close();

3. close.connection() 4. close.Connection()

8. select proper missing statement:


import java.net.*;
class InetAddressTest
{
public static void main(String args[]) {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
InetAddress SW[] = InetAddress.___________("www.nba.com");
for (int i=0; i<SW.length; i++)
System.out.println(SW[i]);
}
}

1. getAllByName() 2. getByName()

3. getName() 4. getAllName()

4
9. Which method of the servlet is/are called several times in its life?

1. init() 2 . destroy()

3. service() 4. All options

10. What is proper method to retrieve the host name of local machine

1. static InetAddress getLocalHost( )throws UnknownHostException 2 static InetAddress LocalHost(


UnknownHostException

3 . static InetAddressget ByName(String hostName)throws 4 . static InetAddressget getHost(


UnknownHostException hostName)throws UnknownHost

11. Connection object can be initialized using the ............................ method of the Driver Manager class.

1. putConnection() 2 . setConnection()

3. Connection() 4 . getConnetion()

12. Consider the following program. Identify the exception that might be thrown
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws ______________________
{
URL netAddress= new URL(“http://www.sun.com:8080//index.html”);
System.out.println(“Protocol :”+netAddress.getProtocol());
System.out.println(“Port :”+netAddress.getPort());
System.out.println(“Host :”+netAddress.getHost());
System.out.println(“File :”+netAddress.getFile());
}}

1. IOException 2 . MalformedURLException

3. Arithmetic Exception 4. UnknownHostException

13. Which of the following methods are main methods in life cycle of servlet?
1. init()
2. service()
3. destroy()
5
4. stop()
5. wait()

1. All (1), (2), (3), (4) and (5) 2. Only (1), (2) and (3)

3. Only (3), (4) and (5) 4. Only (1), (4) and (5)

14 Which of these method of DatagramPacket is used to obtain the byte array of data contained in a datagr

1. getData() 2. getBytes()

3. getArray() 4. receiveByets()

15. Which of the following describes the correct sequence involved for inserting record in stud table having two co
rollNo and sname?
1. Statement stmt=con.createStatement( );
2. Connection con=DriverManager.getConnection(url);
3. int res=stmt.executeQuery(qry);
4. Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
5. String qry= “insert into stud values(12,‘xyz’);

1. 1-2-3-4-5 2. 4-2-5-3-1

3. 4-2-1-3-5 4. 4-2-1-5-3

16. For the following code, fill up the correct listener name and event name.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="SimpleKeyDemo" width=300 height=100>
</applet> */
public class SimpleKeyDemo extends Applet implements _____________
{
String msg = "";
int X = 10, Y = 20;
public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed( _________ ke)
{
showStatus("Key Down");
}
public void keyReleased( _________ ke)
6
{
showStatus("Key Up");
}
public void keyTyped( ____________ ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}

1. KeyEvent, ItemListener 2. TextListner, KeyEvent

3. Adjustment, AdjustmentEvent 4. KeyListener, KeyEvent

17. ________________ method belongs to which event KeyEvent class?

1. getKeyChar( ) and getkeyCode( ) 2. readNumber() and readChar()

3. readKey() and readChar() 4. getKey() and getCode()

18. Which of the method not applicabe to MouseListener

1. mouseEntered() 2. mouseExited()

3. mouseDrop() 4. mouseClicked()

19. In following Java program fill statement showing ***.Select any one option fro given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
7
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}

1. new Cookie("MyCookie", data); 2. new Cookie("MyCookie", dat

3. new Cookie("MyCookie", data2); 4. new Cookie("MyCookie", data

20. Select the correct syntax of adjustmentValueChanged( ) method.

1. void adjustmentvaluechanged(AdjustmentEvent ae) 2. void


adjustmentValueChanged(Adjust
ae)

3. String adjustmentvalueChanged(AdjustmentEvent ae) 4.


int
adjustmentValueChanged(Adjust
ae)

21 In following Java program fill statement showing ***.Select any one option fro given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = ***************
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A. new Cookie("MyCookie", data);
B. new Cookie("MyCookie", data1);
C. new Cookie("MyCookie", data2);
D. new Cookie("MyCookie", data2);
22 Choose the missing statements in following code from given options.
import java.io.*;
import javax.servlet.*;
8
import javax.servlet.http.*;
public class WritingCookies extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse
response)throws ServletException, IOException
{
Cookie cookie = new Cookie("dept-codes","CO-CD-CM-IF");
response.setContentType("text/html");
3
PrintWriter pw = response.getWriter();
pw.println("One cookie is set.");
pw.close();
}
}
A.response.insertCookie(cookie);
B.response.addNewCookie(cookie);
C.response.addNewCookie(cookie);
D.response.addNewCookie(cookie);
23 Choose the missing statements in following code from given options.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WritingCookies extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse
response)throws ServletException, IOException
{
Cookie cookie = new Cookie("dept-codes","CO-CD-CM-IF");
response.setContentType("text/html"); 3
PrintWriter pw = response.getWriter();
pw.println("One cookie is set.");
pw.close();
}
} A.response.insertCookie(cookie); B.response.addNewCookie(cookie);
C.response.addNewCookie(cookie); D.response.addNewCookie(cookie);
24 while(rs.next())
{
String n=rs.getString("name");
System.out.println("name:"+n);
String n1=rs.getString("rollnumber");
System.out.println("rollnumber:"+n1);
}
What does the above code do? A. Display Record B. create connection
C. prepare the statement object D. none of the above
25 Which Statement is given the error in the following code
import java.sql.*;
class dataI
{
public static void main(String a[])
9
{
try
{
Driver d= new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
Connection con =DriverManager.getConnection("Jdbc:Odbc:xxx");
Statement s=con.createStatement();
s.executeUpdate("Insert into Table1 values('hhh',12)");
if(n==1)
{
System.out.println("Record inserted ");
con.close();
}
}
catch(Exception e)
{
System.out.println("not Inserted"+e);
}
}
} A. Statement Object B. Sql Query Statement and variable 'if'
creation statement
C. Connection Statement D. Table Statement
26 Identify the correct sequence for querying the database
There are seven standard steps in querying databases:
A. • Load the JDBC driver.
• Define the connection URL.
• Establish the connection.
• Execute a query or update.
• Create a statement object.
• Process the results.
• Close the connection.
B. • Load the JDBC driver.
• Define the connection URL.
• Establish the connection.
• Create a statement object.
• Execute a query or update.
• Process the results.
• Close the connection.
C. • Load the JDBC driver.
• Establish the connection.
Define the connection URL.
• Create a statement object.
• Execute a query or update.
• Process the results.
• Close the connection.
D. • Load the JDBC driver.
• Define the connection URL.
Establish the connection.
• Process the results.
1
0
• Create a statement object.
• Execute a query or update.
• Close the connection.
27 which are the syntax of close() method in conection interface methode
A. conectionclose();
B. closeconection()
C. close ()
D. all the above
28 What will be the output of the following program
import java.net.*;
class networking {
public static void main(String[] args) throws UnknownHostException {
InetAddress obj1 = InetAddress.getByName("google.com");
InetAddress obj2 = InetAddress.getByName("google.com");
boolean x = obj1.equals(obj2);
System.out.print(x);
6
}
}
A.true
B.false
C.0
D.1
29 select proper missing statement:
import java.net.*;
class InetAddressTest
{
public static void main(String args[]) {
InetAddress Address = InetAddress.getLocalHost();
System.out.println(Address);
InetAddress SW[] = InetAddress.___________("www.nba.com");
for (int i=0; i<SW.length; i++)
System.out.println(SW[i]);
}
}
A. getAllByName()
B. getByName()
C. getName()
D. getName()
30 For the following code, fill up the correct listener name and event name.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code="SimpleKeyDemo" width=300 height=100>
</applet> */
public class SimpleKeyDemo extends Applet implements _____________
{
String msg = "";
int X = 10, Y = 20;
1
1
public void init()
{
addKeyListener(this);
requestFocus();
}
public void keyPressed( _________ ke)
{
showStatus("Key Down");
}
public void keyReleased( _________ ke)
{
showStatus("Key Up");
}
public void keyTyped( ____________ ke)
{
msg += ke.getKeyChar();
repaint();
}
public void paint(Graphics g)
{
g.drawString(msg, X, Y);
}
}
A. KeyEvent, ItemListener
B. TextListner, KeyEvent
C.Adjustment, AdjustmentEvent
D.KeyListener, KeyEvent
31 What will happen when any item from list is selected import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
/*<applet code="cho" width=300 height=300></applet>*/
public class cho extends Applet implements ItemListener
{
TextField t1;
Choice l1;
9
public void init()
{
t1=new TextField(10);
l1=new Choice();
l1.add("sangamner");
l1.add("nasik");
l1.add("pune");
l1.add("mumbai");
add(l1);
add(t1);
l1.addItemListener(this);
}
public void itemStateChanged(ItemEvent e)
1
2
{
if(e.getItemSelectable()==l1)
t1.setText(((Choice)e.getItemSelectable()).getSelectedItem());}}
A. No Item from list can be selected
B. Selected item will be displayed in textfield
C. Selected item will be displayed in textfield
D. Selected item will be displayed in textfield
32 Which method of the servlet is/are called several times in its life?
A.init()
B.service()
C.destroy()
D.Both I & ii
33 Difference between doGet() and doPost() methods is___________________.
Select any of given options
A. In doGet() the parameters are appended to the URL and sent along with
header information.
B. In doPost(),will send the information through a socket back to the webserver
and it won't show up in the URL bar.
C. doGet() is a request for information;
D. doPost() provides information (such as placing an order) that the server is
expected to remember
A. All above are valid differences
B. Only A and B
C. Only C and D
D. A, B, C are valid differences.
34 in which layer two tier model are divided into two parts
A. application layer & session layer
B. application layer & presentation layer
C. application layer &database layer
D. ALL OF ABOVE
35 Which of the following describes the correct sequence involved for inserting
record in stud table having two columns rollNo and sname? 1. Statement
stmt=con.createStatement( );
2. Connection con=DriverManager.getConnection(url);
3. int res=stmt.executeQuery(qry);
4. Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
5. String qry= “insert into stud values(12,‘xyz’);
A. 1-2-3-4-5
B. 4-2-5-3-1
C. 4-2-1-3-5
D. 4-2-1-5-3
36 Which code segment could execute the stored procedure "countRecs()" located
in a database server?
A. Statement stmt = connection.createStatement();
stmt.execute("COUNTRECS()");
B. CallableStatement cs = con.prepareCall("{call COUNTRECS}");
cs.executeQuery();
C. StoreProcedureStatement spstmt =

1
3
connection.createStoreProcedure("countRecs()");
spstmt.executeQuery();
D. PrepareStatement pstmt = connection.prepareStatement("countRecs()");
pstmt.execute();
37 If port number is not specified in the URL, getPort() method returns _______
A. -1
B. 8080
C. 80
25
38 In following Java program fill statement showing ***.Select any one option from
given options.
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
******************
System.out.println(""Protocol :""+netAddress.getProtocol());
System.out.println(""Port :""+netAddress.getPort());
System.out.println(""Host :""+netAddress.getHost());
System.out.println(""File :""+netAddress.getFile());
}
}
A.URL netAddress=new URL(http://www.sun.com.8080//index.html);
B.URL netAddress=new URL(http://www.sun.com.//index.html);
C.URL netAddress=new URL(http://www.sun.com//*.html);
D.URL net=new URL(http://www.sun.com.8080//index.html)
39 When the event source generates an event, the event source notifies to
..............that the event has occurred.
A. all the listener objects
B. selected listener objects
C. single listener object
D. none of these
40 Select the correct syntax of adjustmentValueChanged( ) method.
A. void adjustmentvaluechanged(AdjustmentEvent ae)
B. void adjustmentValueChanged(AdjustmentEvent ae)
C. String adjustmentvalueChanged(AdjustmentEvent ae)
D. int adjustmentValueChanged(AdjustmentEvent ae)
41 A ___________________ is a small piece of information that is persisted
between the multiple client requests.
A. cookie
B. cookie
C.parameter
D.JSP

42 Life cycle of the servlet is managed by


A. servletContext
B. servletContainer
C. Supporting protocol

1
4
D. all of the above
43 boolean isLast() method of ResultSet ____________ .
A. shifts the control of a ResultSet cursor to the last row of the ResultSet
B. determines whether the ResultSet cursor points to the last row of the
ResultSet.
C. shifts the controls of a ResultSet cursor after the last row of the ResultSet
D. all of these
44 Which of the following is factory method of InetAddress class
A. getAddress()
B. getLocalPort()
C. getByName()
D. getHostname()
45 Which methods are commonly used in ServerSocket class?
A.public OutputStream getOutputStream()
B.public Socket accept()
C.public synchronized void close()
D.None of the above
46 Which of the following is not a constructor of DatagramSocket
A. DatagramSocket( )
B. DatagramSocket(int port)
C. DatagramSocket(InetAddress address)
D. DatagramSocket(int port, InetAddress ipAddress)
47 _________ is a protocol that sends independent packets of data, called
datagrams.
A.tcp
B.IP
C.UDP
D.HTTP
48 Which of the following statement is false? 1)AdapterClass provides easy
implementation of methods of EventListener interface
2)EventSource is a object used to create and generate event.
3)KeyEvent is superclass of InputEvent
4)ComponentEvent is superclass of WindowEvent
A.1
B.2
C.3
D.4
49 ill in correct code at blank spaces
import java.net.*;
public class getDatagramExample {
public static void main(String args[]) {
String s = "This is a test.";
byte[] data = new byte[s.length()];
s.getBytes(0, s.length(), data, 0);
try {
InetAddress ia = InetAddress.-------------("www.msbte.com");
int port = 7;
DatagramPacket dp = new DatagramPacket(data, data.length, ia, port);

1
5
System.out.println("This packet is addressed to " + dp.getAddress() + " on port "
+ dp.getPort());
System.out.println("There are " + dp.getLength() + " bytes of data in the
packet");
System.out.println(new String(dp.getData(), 0, 0, dp.getLength()));
}
catch (----------------------------------- e) {
System.err.println(e);
21
}
}
}
A. getname,unkwonException
B. getByName, UnknownHostException
C. getbyall,knownhostexception
D. none is correct
50 Which of the following is the correct syntax of executeQuery() method?
A. int executeQuery()
B. int executeQuery(String str)
C. ResultSet executeQuery()
D. ResultSet executeQuery(String str)
51 In the following program choose the correct strings from given options to pass in
URL constructor to get an output without any exception.
import java.net.*;
class URLDemo
{
public static void main(String args[]) throws MalformedURLException
{
URL hp = new URL("__________");
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort());
System.out.println("Host: " + hp.getHost());
System.out.println("File: " + hp.getFile());
}
}
A. http://www.msbte.com/mainsite/index.php
B. http://www.msbte.com:80/mainsite/index.php
C. www.msbte.com/
D. www.msbte.com/mainsite/index.php
A. Only A
B. Only B
C. Either A or B
D.All
52 Which protocol will be used/printed in the following example
import java.net.*;
public class URLDemo {
30
public static void main(String args[]) throws MalformedURLException {
URL hp = new URL("http://www.msbte.com/downloads");
1
6
System.out.println("Protocol: " + hp.getProtocol());
System.out.println("Port: " + hp.getPort());
System.out.println("Host: " + hp.getHost());
System.out.println("File: " + hp.getFile());
System.out.println("Ext:" + hp.toExternalForm());
}
}
A. FTP
B. SMTP
C. TFTP
D.HTTP
53 what is the output of following code
Try{
String sql=”update emp set salary=? Where id=?”;
PreparedStatement pstmt=con prepareStatement(sql) ; }
Catch(SQL Exception e) { }
A. update emp by accepting salary
B. update emp by accepting id and salary as aparameter
C. update emp by accepting salary and id as a parameter
D. None of the above
54 What will be the result of executing the following code snippet?
Statement sql2 = con.createStatement();
int result=sql2.executeUpdate("Select * From Publishers");
A. Will throw an exception
B. Will result in compilation error
C. Will return the number of rows retrieved from Publishers table
55 In following Java program fill statement showing ***.Select any one option fro
given options
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends *********
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throwsServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = new Cookie("MyCookie", data);
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A. GenericServlet
B. HttpServlet
C. FtpServlet
1
7
D. HTMLServlet
56 Choose missing statements in following code from given options.
public class cookies servlet extends HTTPServlet
{
public void doGet(HTTPServletRequest reg,HTTPServletResponse res) throws
ServletException, IOexception {
Cookie token=null
res.setContentType("text/html");
Printwriter pw=res.getwriter();
pw.println("<html><body>");
String s=request.getParameter("name");
token=new Cookie("MyCookie",s);
res.addCookie(token);
pw.println(""Information collected by the Cookie:"");
pw.println(""Cookie Name:""+token.getName());
pw.println(""Cookie Value:""+token.getValue);
pw.println(""</body></html>"");
pw.close();
}
}
A. import java.io.*;
B. import javax.servlet.http.*;
C. import javax.servlet.*;
D. All of the above.
57 Calling ServerSocket() constructor with port value 'zero'
means______________________.
A.use a port number zero that is automatically allocated.
B.use a port number zero that is automatically destroyed.
C. use a port number zero that is automatically connection created.
D.use a port number zero that is automatically stop.
58 Type 1 driver is known as__________________?
A. JDBC-Native API
B. JDBC-ODBC Bridge Driver
C. JDBC-net pure java
D. None of these
59 getWriter() method can be called by --------------------object
A. ServletResponse object
B. ServletRequest object
C. ServletConfig object
D. none of the above
60 Which is not the method in servlet to handle http request
A. doPost()
B. doGet()
C. doPut()
D. doShow()
61 On typing a URL on the address bar, which HTTP request gets generated? Select
the one correct answer
A. GET method

1
8
D. POST method
B. HEAD method
C. PUT method
62 ……class is used to encapsulate IP address and DNS.
A.DatagramPacket
B.URL
C.InetAddress
D.Socket
63 How many bits are in a single IPv4 address?
A.8
B.16
C.32
D.64
64 The ______________ method sets the query parameters of the
PreparedStatement object.
A. putString()
B. insertString()
C. setString()
D. setToString()
65 Which code is correct from the following options to make use of
PreparedStatement
A. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=*";
st=con.prepareStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
B. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
1
9
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.collableStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
C. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.createStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');

D. import java.sql.*;
import java.io.*;
public class DBDemo
{
public static void main(String []args)throws Exception
{
String sql;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:stud";
Connection con=DriverManger.getConnection(url);
PreparedStatement st;
sql="select * from stud_table where name=?";
st=con.prepareStatement(sql);
st.setInt(1,2);
st.setString(2,'ganesh');
43
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
}
2
0
st.setString(3,'pune');
ResultSet rs=st.executeQuery();
st.close();
}
66 Which statements are required in following program to retrive records from
table import java.sql.*;
public class JDBCExample {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(jdbc:odbc:stud”);
System.out.println(" Records of table...");
stmt = conn.createStatement();
______________________________________________________
__________________________________________________________________
System.out.println("Inserted records into the table...");
System.out.println("Goodbye!");
}}
A. ResultSet rs=stmt.executeQuery("select * from student");
B. ResultSet rs=stmt.execute("select from student");
C. ResultSet rs=stmt.executeUpdate("select * from student");
D. None of these

67 Consider the following program ,what should be the correction done in the
program to get the correct output
import java.sql.*;
public class displayemployee
{
public static void main(String[] args)
{
Connection con;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Connection established");
}
catch(Exception e)
{
System.out.println("Connection error");
}
try
{
String str="jdbc.odbc:dsn1";
con=DriverManager.getConnection(str,"","");
Statement st=con.createStatement();
44
ResultSet rs=st.executeQuery("Select*from employee");
2
1
int n=rs.getMetaData().getColumnCount();
for(int i=1;i<=n;i++)
{
System.out.print(rs.getMetaData().getColumnLabel(i)+'t');
System.out.println("");
while(rs.next())
{
for(int i=1;i<=n;i++)
{
System.out.print(rs.getString(i)+'t');
}
System.out.println("");
}
rs.close();
con.close();
}
catch(SQLException e)
{
System.out.print("SQL error");
}
}
}
A. missing }
B. missing {
C. missing semicolon
D. missing package statement
68 Consider following code of servlet and find out missing method in the program
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Mathservlet extends HttpServlet
{
public void (HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><h1>Table Example</h1>");
out.println("<table border = 1>");
out.println("<tr><td> Number </td><td> Result <td></tr>");
for(int i=1;1<10;i++)
{
out.println("<tr><td>"+ i + "t" + Math.pow(2,i) + "<td><tr>");
}
out.println("</table></html>");
printwriter.close();
}
}
A. service()
2
2
B.delete()
C.init()
D.destroy()
69 Choose missing statements in following code from given options.
public class cookies servlet extends HTTPServlet
{
public void doGet(HTTPServletRequest reg,HTTPServletResponse res) throws
ServletException, IOexception {
Cookie token=null
res.setContentType("text/html");
46
Printwriter pw=res.getwriter();
pw.println("<html><body>");
String s=request.getParameter("name");
token=new Cookie("MyCookie",s);
res.addCookie(token);
pw.println(""Information collected by the Cookie:"");
pw.println(""Cookie Name:""+token.getName());
pw.println(""Cookie Value:""+token.getValue);
pw.println(""</body></html>"");
pw.close();
}
}
A. import java.io.*;
B. import javax.servlet.http.*;
C. import javax.servlet.*;
D. All of the above.
70 What is output of following code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddCookieServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String data = request.getParameter("data");
Cookie cookie = new Cookie("MyCookie", data);
response.addCookie(cookie);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("<B>MyCookie has been set to");
pw.println(data);
pw.close();
}
}
A. this code will add Cookie named MyCookie
B. this code will delete Cookie named MyCookie
C. this will only create Cookie
2
3
D. this will destroy Cookie
71 What happens if the following code is executed?
import java.sql.*;
public class S1Q57{
public static void main(String[] args) {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:shree");
Statement stm = con.createstatement();
String query ="select rollno,name,percent from student ";
ResultSet rs = stm.executeQuery(query);
while(rs.next()){
System.out.println("Roll No = "+rs.getInt(1));
System.out.println("Name = "+rs.getString(2));
System.out.println("per = "+rs.getDouble(3));
}
con.close();
}
}
A. There is a compiler error
B. There is a run time error
C. Program run Successfully and print the content of table
D. Retrieval of the fields is in the wrong order
72 Consider the following database:
ID name Salary
1 ramesh 1200
2 ganesh 1111
6 sanjay 9500
What will be the correct output for following code:
import java.sql.*;
class SelectDemo
{
public static void main(String a[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
String url="jdbc:odbc:mydsn";
Connection con=DriverManager.getConnection(url);
System.out.println(" Connection to DataBase created");
Statement stmt=con.createStatement();
String query="select * from emp";
ResultSet rs=stmt.executeQuery(query);
50
while(rs.next())
{
System.out.println(" ID : "+ rs.getInt(1));
System.out.println(" name : "+ rs.getString(2));
System.out.println(" Salary : "+ rs.getInt(3));
2
4
System.out.println();
}
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
A. Driver Loaded
Connection to DataBase created
ID : 1
name : ramesh
Salary : 1200
ID : 2
name : ganesh
Salary : 1111
ID : 6
name : Sanjay
Salary : 9500
B. Driver Loaded
Connection to DataBase created
ID : 5
name : ramesh
Salary : 1200
ID : 4
name : ganesh
Salary : 1111
ID : 3
name : Sanjay
Salary : 9500
C. Driver Loaded
Connection to DataBase created
ID : 1
name : ramesh
Salary : 1200
ID : 2
name : ganesh
Salary : 1111
ID : 3
name : Sanjay
Salary : 9500
D. Driver Loaded
Connection to DataBase created
ID : 1
2
5
name : ramesh
Salary : 1200
ID : 2
name : sanjay
Salary : 1111
ID : 6
name : ganesh
Salary : 1111
73 Connection con = DriverManager.getConnection ("jdbc:odbc:wombat", "login",
"password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");
while (rs.next())
{
Integer x = rs.getInt("c");
String s = rs.getString("a");
Float f = rs.getFloat("b");
}
What is WRONG with the code above?
A. Retrieval of the fields is in the wrong order.
B. The password must be encrypted before being sent to the DriverManager.
C. The Driver's URL is in the wrong format.
D. The ResultSet class returns primitive types for integers and floats.
74 This is an example of Statement interface that?
import java.sql.*;
class PreStat
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection("jdbc:odbc:student"," "," ");
Statement s=c.createStatement("select * from studTable");
ResultSet rs=s.executeQuery();
System .out.println("Name" + " t " + "Roll_No");
while(rs.next())
{
System.out.println(rs.getInt(1)+" t "+rs.getString(2));
}
s.close();
c.close();
}
}
A. deletes the record
B. retrieve the record
C. updates the record
D. inserts the record
75 Which of the following manages a list of database drivers in JDBC?
A. Collection
B. DriverManager
2
6
C. JDBC Driver
D. Statement
76 Which JDBC driver Type(s) is(are) the JDBC-ODBC bridge?
A. Type1
B. Type2
C. Type3
D. Type4
77 Which of following is not true for servlet?
A. it is persitent
B. platform independence
C. high performance
D. it is single threaded

2
7

You might also like