Two Laptop Bag
The moose likes Servlets and the fly likes How i can connect my servlet to mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How i can connect my servlet to mysql database" Watch "How i can connect my servlet to mysql database" New topic

How i can connect my servlet to mysql database

Rashmi Pant

Joined: Dec 19, 2007
Posts: 25
Will anybody please tell me how i can connect my servlet to mysql database.
i am using jdk1.5,tomcat5 & mysql4.0.18.The installation directory for thes are as:
C:\Program Files\Java\jdk1.5.0_12
I am putting all my servlet file inside testpackage,package so the folder sequence is like :
i have created student database and it is in C:\mysql\data directory
this database contains a simple table name detail with column like roll,name,address.
Now i want to connect this table with servlet and want to display the data from this table to my browser.
Please tell me where i should place the database,what change i should make in web.xma(if it is required).
For example say if i want to connect displatRecord servlet(means, this will be inside testpackage, package) to detail table and want to display the records in browser then what should i do.
I know java connectivity with access database but i do not knoe how this can be done with servlet when i am using a local server.
Thanks to all
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

You dont connect servlet to database but use jdbc for database access.
Look at this tutorial Servlet tutorial

[Servlet tutorial] [Servlet 3.0 Cook Book]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

This page shows how to set up Tomcat's internal database connection pool.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: How i can connect my servlet to mysql database
It's not a secret anymore!