• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql query --on the fly

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from a java program I want to make a SQL query on the fly . I mean the query will be setup based on my logic ( it should not be like I wrote a query in the program and I will make a JDBC call to access a DB ). now what is the best design to do that . I'll use IntelJIdea with MySQL . and what is a DAO .
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//SQL Query
String sqlQuery = "";

// put your business logic here to build the sqlQuery string

// Create a SQL statement context to execute the Query
Statement stmt = connection.createStatement();

// Execute the formed query and obtain the ResultSet
ResultSet resultSet = stmt.executeQuery( sqlQuery )
 
prasanna pati
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Lynette Dawson never expected I will get a reply sooo early . anyway then how to show the query result in the Jsp page or like that ? and

actually in that project I have to make one extra layer of abstruction like

view--control---business-logic----------extra layer-----------database

now
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
lets say that your query gets a bunch of employee objects (select * from employees)

loop through the resultset, construct a collection of employee objects and put it in the request attribute

ie.,

Set<Employees> employeeSet = someMethodthatGetsEmployeeSetFromRecordSet(rs);
request.setAttribute("employeeSet",employeeSet);


And in your jsp. get this attribute out of the request:

<% Set<Employees> employeeSet = request.getAttribute("employeeSet"); %>

and use the JSTL tags to loop through this set and display the results
 
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic