473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using sql result set in jsp code

I am havign trouble understanding how to call a string that was queried with the sql in my jsp.

I have a result set
Expand|Select|Wrap|Line Numbers
  1. <%
  2. while (rs.next()) {
  3. String test = rs.getString("user");
  4. out.println(test);
  5. }
  6. %>
  7.  
and the string can be printed here how ever I need to call the "test" string in jsp some jsp code further down the page and it can not see the string variable is there a way to pass the queried string into the jsp? Sorry Im not a big JSP coder so Im just trying to get it working. thanks
Nov 16 '07 #1
2 3182
r035198x
13,262 8TB
I am havign trouble understanding how to call a string that was queried with the sql in my jsp.

I have a result set
Expand|Select|Wrap|Line Numbers
  1. <%
  2. while (rs.next()) {
  3. String test = rs.getString("user");
  4. out.println(test);
  5. }
  6. %>
  7.  
and the string can be printed here how ever I need to call the "test" string in jsp some jsp code further down the page and it can not see the string variable is there a way to pass the queried string into the jsp? Sorry Im not a big JSP coder so Im just trying to get it working. thanks
If you have
Expand|Select|Wrap|Line Numbers
  1.  <%
  2. String test = null;
  3. while (rs.next()) {
  4.   test = rs.getString("user");
  5. out.println(test);
  6. }
  7. //can use test here
  8. %>
then you can use test after the while loop.
Note however, a resultset may contain multiple rows so test will have the value of the last row only
Nov 17 '07 #2
JosAH
11,448 Expert 8TB
From a design perspective no JSPs should contain database handling stuff. JSPs
should concentrate on the view of the application. Servlets, which should act as
the controllers should delegate to beans that should contain the backend logic,
the model; the model should ideally encapsulate that darn SQL stuff (DAOs,
DTOs and DVOs).

Whenever I see sql (jdbc) code in a JSP I go "*OMG*! not again! eeeeww!"

kind regards,

Jos
Nov 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Carlos Ribeiro | last post by:
As a side track of my latest investigations, I began to rely heavily on generators for some stuff where I would previsouly use a more conventional approach. Whenever I need to process a list, I'm...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
2
by: Tugrul HELVACI | last post by:
I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String...
1
khalidbaloch
by: khalidbaloch | last post by:
hi every one, how are you folf , hope fine dear Friends i want to get values of multi-dimensional arrays using foreach loop and after that print out the html using an other while loop , i tried...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
6
by: BOMEz | last post by:
So i've recently been starting to program PHP in an object oriented way, but I'm running into some difficulties in from a design stand point and from an object oriented stand point: Issue 1: In my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.