Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pretty Basic but help needed

 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might be pretty simple for some of you so sorry if its boring. Here is my question. I have a JSP that I submit two pieces of information via a form, the form should go to the servlet that servlet will take those two pieces of information and return a result either a string or null 0 result. It should then return the result to the JSP, or email that result.

Not sure this works, I keep get null as a value on a query that I know should return something.

##################################################################
public class PasswordReminder implements java.io.Serializable {

public String ForgottenReminder;

public PasswordReminder() {}

public String getPassword(int Type, String Input) throws DataLayerException {
Connection Connection = null;
Connection = ConnectionFactory.getConnection();
int type = Type;
String input = Input;
synchronized(Connection) {
try {
Statement Statement = Connection.createStatement();
if (type == 1) {
ResultSet rs = Statement.executeQuery("SELECT password FROM customer WHERE email='"+input+"'");
ForgottenReminder = rs.getString(1);
rs.close();

} else {
ResultSet rs = Statement.executeQuery("SELECT password FROM customer WHERE customernumber='"+input+"'");
ForgottenReminder = rs.getString(1);
rs.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
return ForgottenReminder;
}

public String getPasswordReminder() {
return ForgottenReminder;
}
}
###############################################################

###############################################################
<jsp:useBean class="com.gc.present.PasswordReminder" id="password" scope="session"></jsp:useBean>

<form method="post" "enctype="multipart/form-data" action="password.jsp">
<input type="hidden" name="useage" value="admin">
<input type="text" name="input"><br>
<select name="type">
<option value="1" SELECTED>E-mail</option>
<option value="2">Customer Number</option>
</select>
<input type="submit" name="submit" value="submit">
</form>
<%
if (request.getParameter("submit") != null) {
%>
Password: <%= password.ForgottenReminder %>
<%
}
%>
############################################################
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Java Ranch!

Result sets start positioned before the first row, even when the query returns only one result.

try adding:



...also, Java canvention calls for the variable ForgottenReminder to be forgottenReminder -- note that lower case 'f'. Not a syntatic issue, but semantically Java programmers will look at "ForgottenReminder" and think that it's a class or something.

Also, just to point out the handy feature of CODE tags. Enclose your code with [CODE] and [/CODE] tags, and it will look like the code above.
 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips.
I made the adjustment that you suggested, however I still get a null value
 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it! Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic