JDBC and JSP interview questions and answers

  1. What is the query used to display all tables names in SQL Server (Query analyzer)?

    	select * from information_schema.tables
  2. How many types of JDBC Drivers are present and what are they?- There are 4 types of JDBC Drivers
    • JDBC-ODBC Bridge Driver

    • Native API Partly Java Driver
    • Network protocol Driver
    • JDBC Net pure Java Driver

  3. Can we implement an interface in a JSP?- No
  4. What is the difference between ServletContext and PageContext?- ServletContext: Gives the information about the container. PageContext: Gives the information about the Request
  5. What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?- request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource, context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource.
  6. How to pass information from JSP to included JSP?- Using <%jsp:param> tag.
  7. What is the difference between directive include and jsp include?- <%@ include>: Used to include static resources during translation time. JSP include: Used to include dynamic content or static content during runtime.
  8. What is the difference between RequestDispatcher and sendRedirect?- RequestDispatcher: server-side redirect with request and response objects. sendRedirect : Client-side redirect with new request and response objects.
  9. How does JSP handle runtime exceptions?- Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP.
  10. How do you delete a Cookie within a JSP?
    	Cookie mycook = new Cookie("name","value");
    	Cookie killmycook = new Cookie("mycook","value");
  11. How do I mix JSP and SSI #include?- If you’re just including raw HTML, use the #include directive as usual inside your .jsp file.
    	<!--#include file="data.inc"-->

    But it’s a little trickier if you want the server to evaluate any JSP code that’s inside the included file. If your data.inc file contains jsp code you will have to use

    	<%@ vinclude="data.inc" %>

    The <!–#include file="data.inc"–> is used for including non-JSP files.

  12. I made my class Cloneable but I still get Can’t access protected method clone. Why?- Some of the Java books imply that all you have to do in order to have your class support clone() is implement the Cloneable interface. Not so. Perhaps that was the intent at some point, but that’s not the way it works currently. As it stands, you have to implement your own public clone() method, even if it doesn’t do anything special and just calls super.clone().
  13. Why is XML such an important development?- It removes two constraints which were holding back Web developments: dependence on a single, inflexible document type (HTML) which was being much abused for tasks it was never designed for; the complexity of full SGML, whose syntax allows many powerful but hard-to-program options. XML allows the flexible development of user-defined document types. It provides a robust, non-proprietary, persistent, and verifiable file format for the storage and transmission of text and data both on and off the Web; and it removes the more complex options of SGML, making it easier to program for.
  14. What is the fastest type of JDBC driver?- JDBC driver performance will depend on a number of issues:
    • the quality of the driver code,

    • the size of the driver code,
    • the database server and its load,
    • network topology,
    • the number of times your request is translated to a different API.

    In general, all things being equal, you can assume that the more your request and response change hands, the slower it will be. This means that Type 1 and Type 3 drivers will be slower than Type 2 drivers (the database calls are make at least three translations versus two), and Type 4 drivers are the fastest (only one translation).

  15. How do I find whether a parameter exists in the request object?
    boolean hasFoo = !(request.getParameter("foo") == null
    	|| request.getParameter("foo").equals(""));


    boolean hasParameter =
    	request.getParameterMap().contains(theParameter); //(which works in Servlet 2.3+)
  16. How can I send user authentication information while makingURLConnection?- You’ll want to use HttpURLConnection.setRequestProperty and set all the appropriate headers to HTTP authorization.
This entry was posted in Database, Java. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

20 Comments on JDBC and JSP interview questions and answers

  1. samir
    Posted 3/14/2005 at 7:02 am | Permalink

    how can the servelt connectting between data base and web bage

  2. radhakrishna
    Posted 3/31/2005 at 4:52 am | Permalink

    if we want to Implement any Interfaces in JSP how would we do
    that. There is provision to extend a class so is there a
    provision to Implemnt a Interface

  3. balakumar
    Posted 4/6/2005 at 7:44 am | Permalink

    how is interface and abstract use?

  4. ashanka
    Posted 4/7/2005 at 1:59 am | Permalink

    Hi Everyone,
    I have an interview next week with HP software , can any bosy help me with the preparations, as to what qs’s can be asked. If anyone can get me the model qs that would be very helpful.

    my address : sha_ash@indiatimes.com

  5. ashanka
    Posted 4/7/2005 at 2:01 am | Permalink

    Hi Everyone,
    I have an interview next week with HP software , can any bosy help me with the preparations, as to what qs’s can be asked. If anyone can get me the model qs that would be very helpful. Anything that’s in context with c, c++, java, jsp, servlets, ejb, html, dhtml, oracle, vb, pl-sql, unix, linux, etc.

    my address : sha_ash@sify.com

  6. Narendhar Reddy
    Posted 4/21/2005 at 5:56 pm | Permalink

    How can we extend a class in JSP?, I think we can’t, because of when JSP transforms into servlet it should extened HttpServlet….

  7. Yeshendra
    Posted 5/10/2005 at 4:07 pm | Permalink


    i want to use the tag to get the values from a list control of html
    that support multiple select … how can i get those values through getter and
    setter methods of my bean class…

    if any one have a clue plz mail me at callingyash@rediffmail.com

  8. KOtresh
    Posted 7/13/2005 at 11:01 pm | Permalink

    can anybody help me regarding J2EE projects. will age be a crietaria for not to be selected ?
    where ever i go i clear two round of tests. then no reply from them. i am not able to under statnd why it is so?

  9. Ramadoss
    Posted 12/4/2005 at 9:10 am | Permalink

    why we are setting session time out. If You set in web.xml it will take that as seconds at the same time if you give that in api that will take as minute. what is the difference between this tw.?

  10. Posted 3/20/2006 at 8:40 am | Permalink

    We can configure the session timeout in web.xml file that is for the whole web application, and the time unit is in minutes.

    you can override this time limit for any specific session by using session.setMaxInactiveInterval(int seconds)

  11. Deepmala
    Posted 4/19/2006 at 9:07 am | Permalink

    what is the difference between Struts1.1 and 1.2?

  12. Posted 4/26/2006 at 1:20 am | Permalink

    We can configure the session timeout in web.xml file that is for the whole web application, and the time unit is in minutes.
    you can override this time limit for any specific session by using session.How to set this setMaxInactiveInterval?????????

  13. rolly purbey
    Posted 6/8/2006 at 6:01 am | Permalink

    next week i am appearing for IBM, can anybody help me what kind of questions can be asked in core java, jsp servlets.

  14. Ranadeep
    Posted 7/20/2006 at 1:24 am | Permalink

    can we override the init method in jsp

  15. Ilangium
    Posted 7/25/2006 at 2:00 am | Permalink

    Why in JDBC connectivity for Connection Interface we didnt implement all the methods in Connection interface

  16. sadiq
    Posted 8/8/2006 at 7:16 am | Permalink

    What is the difference between include directive and include action? In both cases the included jsp is getting compiled if i change something in that included jsp and send a request for the main jsp.
    what i know is :
    1.include directive should be for static resource(example: header and fotter part of any web page like Yahoo logo).
    2.include action is for dynamic resouce(the things which are frequently get changes)
    3.if i change a included jsp (including using include directive).
    and send a request for the main jsp then it will compile the included jsp.
    4.if i change a include jsp (including using include action) without changing the main jsp and send a request then the changes will not be reflected.

    can anybody give me more details on this topic.

  17. abdullah
    Posted 8/8/2006 at 8:43 pm | Permalink

    hi i created jdbc connt to oracle 10g express edition but when i put the code inside web page as jsp code the compilation give me error please can any one show me or send the correct code to me . thanks. plese send the answer to anm414@hotmail.com

  18. Posted 10/26/2006 at 4:20 am | Permalink

    Hi Everybody,

    My name is Praveen Kumar I am working with WIPRO since one year on java/j2ee technologies. I have one question i.e., I will write one package. i can use that package in any of other class just i will import that package and do it. But i won’t import then that time it will importing automatically like java.lang.* package. How it is? Do you know send me to my mail you don’t know just call me i will tell you my mobile number is 9980828611(Bangalore)

  19. Nandy
    Posted 11/6/2007 at 3:32 am | Permalink

    The java.lang.* package is imported automatically by class itself because when we are making a class def we just making an object of ‘Class’ so we are getting the property of the Class itself and doing the overriding…hence the Class object is already defiend to import java.lang Package —– New Delhi

  20. Posted 11/15/2007 at 10:18 am | Permalink

    To Connect with oracle 10g database use jdbc14.jar or jodbc.jar from oracle 10g installation location inside jdbc folder.

    Connection connection = null;
    try {
    // Load the JDBC driver
    String driverName = “oracle.jdbc.driver.OracleDriver”;

    // Create a connection to the database
    String serverName = “″;
    String portNumber = “1521″;
    String sid = “mydatabase”;
    String url = “jdbc:oracle:thin:@” + serverName + “:” + portNumber + “:” + sid;
    String username = “username”;
    String password = “password”;
    connection = DriverManager.getConnection(url, username, password);
    } catch (ClassNotFoundException e) {
    // Could not find the database driver
    } catch (SQLException e) {
    // Could not connect to the database

Post a Comment

Your email is never published nor shared. Required fields are marked *