• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Table lookup and populate drop down in JSP  RSS feed

 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to do a database table lookup and fill the column values to a drop down in JSP.
I need to have both the table lookup and the drop down populate code inside the same JSP file.
Please suggest me.
 
pulijala hari
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Get a connection the DB and access the table and get the results into a Resultset.
2)<SELECT name="Results">
<% while( Resultset.hasNext() ) {
String str = (String)Resultset.next();
System.out.println(str);%>
<option><%= str%></option>

%>

3) Try doing and update..
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is considered extermely poor practice to perform DB access directly within a JSP. Don't fall into that habit.

Rather, factor any access code into Java classes, perferably part of a Model layer not tied to any specific UI.
 
Steve Renard
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Hariprasad and Bear...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!