aspose file tools*
The moose likes JSP and the fly likes JSP / JDBC - beginners question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP / JDBC - beginners question" Watch "JSP / JDBC - beginners question" New topic
Author

JSP / JDBC - beginners question

Giselle Dazzi
Ranch Hand

Joined: Apr 20, 2003
Posts: 168
I have a standalong application using Swing. Im converting it to a web / JSP/Servlets application.
Can my JSP acess my database using the same classes it used to or should I configure in my Tomcat a data source and call my database using the jndi name ?
thx in advance,


Giselle Dazzi<br />SCJP 1.4
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
You should be able to "reuse" your existing classes and use it in a web environment. That's one of the advantages of java.
However, having your jsp accessing a database is not recommended. You will see later in your project that it becomes a nightmare to maintain, because your mixing presentation with business logic.
there are many options available:
- You can have a JavaBean that handles the connection to the database, and you'll use jsp:useBean... in your jsp to access it. for instance, if you already have a class that deals with connection and database stuff, you can reuse it (you will see that it is not that simple).
- deal with connection in your servlets. that's what servlets are for, pure java code. As you said, you can have a datasource (recommended) with a connection pool, so every request will reuse a connection from the pool and will release it once it is done, giving the chance to another request to reuse the same connection.
- tag libraries. There are many existing tag libraries available (free) that deals with connection with database, specifying a datasource as well. You will use these tags inside your jsp. Tags have the XML format, so you will still keep java code out of JSP pages.
- connect to the database from jsp's (discard this immediately )
So, my $0.02 here, have a look at datasource Tomcat documentation, the best way to go ...
hope it helps
[ October 30, 2003: Message edited by: Andres Gonzalez ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
BTW, have a look at this link.
Giselle Dazzi
Ranch Hand

Joined: Apr 20, 2003
Posts: 168
Thank you guys, I´┐Żll look into it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP / JDBC - beginners question