aspose file tools*
The moose likes Beginning Java and the fly likes Pretty Basic but help needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pretty Basic but help needed" Watch "Pretty Basic but help needed" New topic
Author

Pretty Basic but help needed

Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
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

Joined: Aug 20, 2001
Posts: 1821

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
Thanks for the tips.
I made the adjustment that you suggested, however I still get a null value
Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
Got it! Thanks
 
wood burning stoves
 
subject: Pretty Basic but help needed