File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Getting started with JDBC project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting started with JDBC project" Watch "Getting started with JDBC project" New topic
Author

Getting started with JDBC project

Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
Hi,
I will soon be creating a java project which will require a DB for data storage but my question is how do most of you structure the project? By this I mean do you keep the DB on a server and use something like a servlet to access it or can you have a front end which is client based and that can access a BD on a server?
Anyway any thoughts would be much appreciated
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You could write an applet that access the database server directly. There would be security issues to deal with and such a 2-tier system is usually not recommended.
I like thin clients (web browsers) and lots of layers providing lots of indirection. A basic web application framework would likely include the notion of a web browser that communicates with JSPs (and Servlets), with some Servlet controllers responsible for database server communications.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
so I would have an applet from end and then the servlet stuff and then the DB? Sorry I am having real trouble getting my head around this technical stuff but can swing be used for the applet part? and if security doesn't matter that much can the applet manage all the Db stuff too?
Thanks
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
A lot of times you don't need an applet. I'd recommend not using one whenever possible.
A web browser can send requests to a server where a Servlet controller would handle the request, and either dynamically generate some web page as a response or delegate that responsibility to a JSP.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Lengthy post:
Depending on the situation, i would tend to stay from applets. As a front end for a systam, they can provide a lot of headaches and are only really useful for intra-net applications. And if you are building an intra-net application, a standard 2-tier application would be better (less restricted, not have to download applet, etc.)
Client (desktop application) <-> database

There are amny isues with this architecture, including having to deal with concurrency and multiple-users, so when you start dealing with a large number of people (or a true inter-net application), I suggest using an n-tier architecture.
********** RECOMMENDED ***********
Typically, this looks either like:
Client(Web browser) <-> Servlets (web Server) <-> Database
or:
Client(Web browser) <-> Servlets (web Server) <-> EJBs (Application server) <-> Database
**********************************
The former is useful for smaller applications, but the latter is extremely robust. If this is a large-scale project, or if you think that in the future it might be, use the latter.
For the record, you could do:
Client (applet) <-> database,
but as Dick pointed out there are security issues dealing with this.
You could also:
Client (applet) <-> Servlets (web Server) <-> Database
or:
Client(applet) <-> Servlets (web Server) <-> EJBs (Application server) <-> Database
These are useful if you need the GUI capabilities of applets (HTML is not truly a nice UI)
And to answer your question, yes, swing can be used for Applets. You can even use JApplet, the swing applet.

Sorry for the length, but you are correct when you say that there is a lot of technical stuff involved. Choosing the right approach does depend on your specific situation, but in general the Client(Web browser) <-> Servlets (web Server) <-> Database is adequate.
And I like to ramble.
leo donahue
Ranch Hand

Joined: Apr 17, 2003
Posts: 327
Joel,
When you gave these two options:
Client(Web browser) <-> Servlets (web Server) <-> Database
or:
Client(Web browser) <-> Servlets (web Server) <-> EJBs (Application server) <-> Database

What is the difference between a web server such as Tomcat and an Application server? What is an example of an application server? Apache itself?


Thanks, leo
Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
Joel,
Thanks your your post it is slowly getting me to a point of understanding!
I just have one or two more questions....
With the n-tier you say to use
Client(Web browser) <-> Servlets (web Server) <-> Database
What would you typically use for the client? I have only really cretaed DB projects using ASP which handles all of the DB stuff so would you create a HTML page as normal and the servlet handles all the DB stuff?
I have a feeling I will need to do some research into this.....
Also where does the servlet stuff go - I mean do you store everything on a server?
Thanks
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Originally posted by leo donahue:

What is the difference between a web server such as Tomcat and an Application server? What is an example of an application server? Apache itself?

An application server is (basically) a server that handles EJBs. BEA Weblogic and IBM Websphere are two of the most popular ones out there; JBoss is the leading free App server.
The web server just servs up web pages. Typically, Apache is the webserver and Tomcat is the Servlet Container, although you can use Tomcat as a webserver itself (if you are not using PERL/PHP).
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Originally posted by Amy Phillips:
What would you typically use for the client? I have only really cretaed DB projects using ASP which handles all of the DB stuff so would you create a HTML page as normal and the servlet handles all the DB stuff?

Just as a note, this is probably out of the scope of this forum; however, there are too many forums that address these topics (Servlets/JSPs/J2EE/Tomcat/Apache/JBoss/etc...). Browsing these forums might also help you.
As far as architecture, a JSP and an ASP are fairly similar. As in ASP, a web browser would be your client. You would then code JSPs and Servlets to present the data. Your JSPs would also either connect to the database or connect to an app server (see my previous post) which connects to the database.
Your code would be stored on the web server (and app server, if you use one). See Servlets and/or JSP forums if you have questions there.
Hope that this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting started with JDBC project