JSP / JDBC - beginners question

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,

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