• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:






 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know how.
Is there any other way to do this?
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lenny Lee Petersen wrote:Don't know how.


Time to learn.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic