• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Lenny Peter
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Lenny Peter
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know how.
Is there any other way to do this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lenny Lee Petersen wrote:Don't know how.

Time to learn.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic