assign output value to string

aauser
aauser used Ask the Experts™
on
Hi,


   rset = stmt.executeQuery ("select phone from address where name='"+inputname"' ");
        out.println("<TABLE BORDER CELLSPACING=3 CELLPADDING=3>");
        out.println("<TD>"+col1);
        while (rset.next ()) {
             out.println("<TR>");
             for (int i=1;i<=1;i++) {
                out.println("<TD>"+rset.getString
                 (i));
             }


the above display the output of value phone number,
how can I assign this value to a string phonequery so I can print it?

eg: out.print("name query is"+phonequery+


thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Why not

String phoneNumber = rset.getString(1);

?
Top Expert 2016

Commented:
This looks more like it for the first bit of code btw:

rset = stmt.executeQuery ("select phone from address where name='"+inputname"'");
       out.println("<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">);
       while (rset.next ()) {
         out.println("<tr>");
         for (int i=1;i<=1;i++) {
            out.println("<td>"+ rset.getString(i) + "</td>");
         }
         out.println("</tr>");
       out.println("</table>");            
Top Expert 2016
Commented:
You could put the assignment on the loop:

String s = "";
rset = stmt.executeQuery ("select phone from address where name='"+inputname"'");
      out.println("<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">);
      while (rset.next ()) {
        out.println("<tr>");
        for (int i=1;i<=1;i++) {
           s = rset.getString(i);
           out.println("<td>"+ s + "</td>");
        }
        out.println("</tr>");
      out.println("</table>");            
out.println("The phone number is " + s);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial