Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Need Help With Accessing Multiple Access Database Tables Using JSP

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys i need to feed in data from multiple tables on a jsp page..
please help me !!
i know how to do it using one table by using the use bean property and then using the snipplet but i don't know how to do it using multiple tables !!
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Open database connection once and then try using ResultSet(rs),Statement(stmt)
rs.stmt.executequery("Query");
or rs.stmt.executeUpdate("Query")
and while you want to retrieve from that table use while(rs.next)
and finally close database connection
I hope this works !!!
 
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be doing any database access, or even have any Java code at all, in a modern JSP. Do this type of thing in a Java class where it belongs.

In any case, this is not a JSP questions so it's been moved to the JDBC forum.
 
Nishant Vashisth
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if its so then how to use data base in a jsp page ??
it not like we can work around without database !!!

please share any other modern way if you have i'd be obliged to learn it !!
 
Marshal
Posts: 25795
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "modern" way -- which has been the professional way for about eight years now -- is to collect and prepare the data in a servlet, or some other similar component, before forwarding the collected data to a JSP to be made into HTML.

Doing it that way allows you to use ordinary Java/JDBC code to access the database, so you don't have to concern yourself about "how to access the database from a JSP".

As for accessing multiple tables, you might want to use an SQL join or something like that. But the question is far too lacking in detail for anybody to provide a useful answer.
 
Rinkit Shah
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As it is said that it is not a "good practice" to open connection in a jsp page can anyone please help us how to get data into jsp from Servlet.

I am able to save data from jsp to database wih help of data helper class and servlet by help of request.getparameter attribute and setting beans. But I am unable to find a solution of how to display data from servlet to jsp or html file can anyone help in this.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rinkit Shah wrote:As it is said that it is not a "good practice" to open connection in a jsp page can anyone please help us how to get data into jsp from Servlet.

I am able to save data from jsp to database wih help of data helper class and servlet by help of request.getparameter attribute and setting beans. But I am unable to find a solution of how to display data from servlet to jsp or html file can anyone help in this.



Well I'm not sure what is your app architecture, and how do you handle request/response, but just to answer your question(even there are many mvc framework out there that is preferred to use it):


And in request or session object you can store whatever you want.

Regards
 
Bear Bibeault
Marshal
Posts: 67445
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article.
 
Nishant Vashisth
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys you are miss understanding me !!

i am not making connections on a jsp page i am well aware of the way !!

i am making a connection on a java class and forwarding the resultset to the jsp page !!

what i wanted to ask was that i can use data of one table easily but using multiple tables is creating problems !!
 
author & internet detective
Posts: 40169
812
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nishant,
They are not misunderstanding. The problem is still that you are trying to use the JDBC ResultSet on the JSP page. This is causing problems because you want multiple resultsets open at the same time. (and you probably also have a connection link from not closing the connection probably.)

With MVC architecture, you read from the database/resultset storing the result in Java objects completely disconnected from the database. You place those in request.setAttribute() and the JSP reads those beans without any database interaction at all.
 
Nishant Vashisth
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay !!
getting your point to some extent !!
can you send me a link to a tutorial for this ??
 
What are you doing? You are supposed to be reading this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic