Get all updates of Java4s

How to Connect Servlet to the Database with Example

Let us see how to connect servelet application with (Oracle) database, for time being i am considering Oracle XE.  In our application i am going to display all the records from the table ‘Java4s‘.

  • Make sure you have java4s table in the database with some data in it
  • Make sure you have ojdbc14.jar file in your classpath and lib folder as well as [ why in two places ? :-) servlet will use ojdbc14.jar file which is in the classpath, for compiling the application, and ojdbc14.jar file in lib folder will be used at the time of running the servlet application], you can check the same in this figure…

Directory Structure

Files Required

  • index.html
  • web.xml
  • ojdbc14.jar





You Might Also Like

  ::. About the Author .::

- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


16 Responses to “How to Connect Servlet to the Database with Example”
  1. what is the difference between flush and commit?

  2. Akhilesh says:

    Hello sir ! i love ur tutorial..u r doing great work…plz post also jdbc ,jsp and sir in servlet u dont cover all topic..plz also post session ,filter etc..thankx in advance

  3. sidhu says:

    what the means of sqlexception?
    and which situation it will come
    plzz explain

  4. ASRAAR says:

    Hi !!!!!
    Can anyone explain filters in detail with code segments? like we have authentication filter , logging, data compression etc.

  5. Kannan K says:

    Sir ur tutorial is realy useful and could u pls add Servlet Chaining & session tracking in servlet

  6. Raju says:

    hi sir,
    We are eagerly wait for web servies, please provide the implementation of web services ASAP. Thankx a lot.

  7. srikanth says:

    hello sir,
    i want webservice tutorials please provide webservices ASAP,we have so many websites but not equal to your explanation,your explanation is very neat and clearly please provide webservices

    thank youuuuuuuu

  8. MSREDDY says:

    First for providing all topics in software but i need jsp tutorials

  9. RaviReddy says:

    jdbc ok
    can u tell how to connect servlet and hibernate
    login and registration form

  10. nagesh says:

    Very helpful tutorial.Thank you

  11. Sanjeet Kumar says:

    Making connection SQL server Database

    Using the sqljdbc.jar class library, applications must first register the driver as follows:


    When the driver is loaded, you can establish a connection by using a connection URL and the getConnection method of the DriverManager class:

    String connectionUrl = “jdbc:sqlserver://localhost:1433;” +
    Connection con = DriverManager.getConnection(connectionUrl);

  12. Alexander says:

    Many thanks.

  13. Gayatri says:

    Thank you for good explaination.

  14. Manoj Soni says:

    Very help full tutorial but plz update complete topic and plz update jsp tutorial..

  15. Vivek Dubey says:

    thanks sir for good explanation.

  16. Nagababu says:

    Thanks sir, I am expecting JSP tutorial Please….


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.