wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet connecting to a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet connecting to a database" Watch "Servlet connecting to a database" New topic
Author

Servlet connecting to a database

Neelima Garimella
Ranch Hand

Joined: Oct 03, 2000
Posts: 37
Hi,
Is there any way for a servlet to connect to a database, other than connecting through a JDBC-ODBC?
Is it possible for a servlet to download a file, if so, how can it download?
Any one can, please help me.
Neelima
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
A servlet can do any kind of database connection that any Java application can do. JDBC just happens to be the easiest approach.
A servlet can transmit any kind of file that you might get from a normal web server, you just have to set the content headers correctly to reflect the file type, size, etc.
My Java Developer's guide to servlets and JSP - which should be available shortly - has examples.
Bill
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
i think a better approach is 2 use beans ...
bcos u could make is once, coding all ur jdbc functionality ...
and can use it again and again ....
beans r good for servlets but they r best for JSP if u dont want 2 show ur database 2 ur web page designer ...
mannubaba
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
i was told by my teacher to always use type4 drivers when workin on or for the web, so u can forget jdbc-odbc stuff here.
oracle is shipped with its own jdbc driver, for msSQL server u can download one from
www.inetsoftware.com
the driver name is SPRINTA, go n check it, its cool n will help u with ur stuff. adios
Rob Whelan
Ranch Hand

Joined: Oct 18, 2000
Posts: 33
Hey, here's a neat trick when you're trying to download a file from a servlet:
If your normal servlet path is "/servlet/Download", try pointing the browser to "/servlet/Download/the_file.exe" instead. The request will still get directed to your servlet just like before, but now the browser will be expecting an .exe file (and the user will be able to save the file you give them by that name).
You should still set the MIME type correctly, but this basically ensures that the browser will know what it's getting (filename seems to take priority over MIME type).
 
GeeCON Prague 2014
 
subject: Servlet connecting to a database