File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Show JavaBeans + data from DB at the same time = Servelt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Show JavaBeans + data from DB at the same time = Servelt? " Watch "Show JavaBeans + data from DB at the same time = Servelt? " New topic
Author

Show JavaBeans + data from DB at the same time = Servelt?

Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
Hi

How can I retrive data from JavaBeans ("CheckUserLogin.jsp";)and DB ("jdbc:mysql://localhost:3306/cars";)at the same time and show those in Servlet?
Please see the images. It should be text Hi Lenny P. + list of cars. But I cannot use RequestDispatcher and DriverManager.getConnection
together. What can I do? Thanks

Servlet:






Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Lenny Lee Petersen wrote: But I cannot use RequestDispatcher and DriverManager.getConnection
together.


Sure you can. Retrieve the records you wish to display from the DB, add them to the HTTPServletRequest (setAttribute), then forward to the JSP...


OCJP 6 (93%)
Lenny Peter
Ranch Hand

Joined: Apr 22, 2008
Posts: 52
Don't know how.
Is there any other way to do this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60975
    
  65

Lenny Lee Petersen wrote:Don't know how.

Time to learn.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Lenny Lee Petersen wrote:
public void init() throws ServletException
{
super.init();

try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(URL, "mike","mike");
}
catch (Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
}


As far i know,creating a DB connection in init method wont be flexible[please dont do this]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Show JavaBeans + data from DB at the same time = Servelt?