Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Admin Function: Select user from Database + display their details

I have a drop down list for the users in a table called Members and I want their details displayed in a table on the next page and the option to Update these details.
Is the following the best to use...

Page 1) Page with drop down list with users.
            Button to get page with details

Page 2) Users details displayed in text boxes
            Button to Update these details

Page 3) Conformation page .... details updated

I'm having a bit of trouble with the 2nd page, inserting the users details in to the text fields from the drop down list.
any ideas with the query

ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName="+name);

0
acslater
Asked:
acslater
  • 4
  • 3
  • 2
1 Solution
 
bloodredsunCommented:
ResultSet rs = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+name+"'");
0
 
bloodredsunCommented:
Also check your Capitalization and spelling as well as putting quotes around Strings in SQL statements.

Using a PreparedStatement for this sort of thing would save you a lot of time and effort.
0
 
patbinCommented:
String query="SELECT * FROM MEMBER WHERE USERNAME=?;";
PreparedStatement ps=con.prepareStatement(query);
ps.setString(1,name);
ResultSet rs=null;
rs=ps.executeQuery();

hope this will solve ur problem
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
acslaterAuthor Commented:
I've tried each of them but i'm getting a compile error

I have
<%
out.print("Administrator logged in: " + session.getValue("UserName")+ "<br>");
%>

used at the top of the page as a session vaiable, to show the username of the admin logged in.
Would that make a difference?
Some sample code I have to populate the text fields is ...

//db connection

 ResultSet rs24 = statement.executeQuery("SELECT * FROM Member WHERE UserName='"+name+"'");


%>
                    <table width="81%" border="0" align="center" cellpadding="0" cellspacing="0">
<%while (rs24.next ()){%>

                      <tr>
                        <td colspan="3" valign=bottom class="subtitle"><div align="center">
                            <p><strong>Please Review Your Details</strong></p>
                            <p>&nbsp;</p>
                        </div></td>
                      </tr>
                      <form name="frm1" id="frm1" method="post" action="changed2.jsp" onSubmit="return validateForm(frm1)">
                        <tr align="left" valign="top">
                          <td valign="center" height="35" colspan="4">
                            <p>
                            <table width="97%" height="362" border="0" align="center" cellpadding="3" cellspacing="0">
                              <tr>
                                <td align=right bgcolor="#ffffff" valign="bottom" width="31%" class="subtitle">
                                  <div align="left"><b> Username:</b></div></td>
                                <td align=left valign=bottom width="45%" >
<b>
//<% out.print(  session.getValue("UserName")+ "<br>");%>

out.println("name");
</b>
                                </td>
<td width="24%" colspan="4" rowspan="2" align=right valign=top>&nbsp; </td>
                              </tr>
                              <tr>
                                <td height="4" colspan="2" align="right" valign="bottom" bgcolor="#ffffff" class="subtitle"><div align="left"></div>                                  <div align="left"></div></td>
                               
                              </tr>
                              <tr valign="bottom">
                                <td align="right" bgcolor="#ffffff" valign="bottom" class="subtitle">
                                  <div align="left"><b>First Name:</b></div></td>
                                <td align="left" valign="bottom" colspan=2>
                                  <input name="FirstName" size="30" maxlength="30" tabindex="4" value="<%=rs21.getString ("FirstName")%>">
                                </td>
                              </tr>

// .... etc


0
 
bloodredsunCommented:
what's the compile error. it's probably just where you've missed a semi-colon or have misspelt a method call. The exception stack trace will tell you
0
 
acslaterAuthor Commented:
well this is the error if its any help ...

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
    [javac] Compiling 1 source file



      at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
      at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
      at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
      at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
      at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:457)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:576)
      at java.lang.Thread.run(Thread.java:534)
0
 
patbinCommented:
try using following

String name=Session.getAttribute("UserName");
System.out.println(name);

if it is printing name then ur code is correct
try out this and let me know
0
 
acslaterAuthor Commented:
worked it out, result set was wrong ...
0
 
bloodredsunCommented:
Then why have you accepted patbins answer with a C grade?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now