File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP / JDBC - beginners question

 
Giselle Dazzi
Ranch Hand
Posts: 168
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, have a look at this link.
 
Giselle Dazzi
Ranch Hand
Posts: 168
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys, I´┐Żll look into it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic