wood burning stoves
The moose likes Struts and the fly likes missing return statement { Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "missing return statement {" Watch "missing return statement {" New topic

missing return statement {

Prashant K. Singh

Joined: May 11, 2009
Posts: 18
Hi I have written an action class for struts 2.0 but I am getting a compiler errror which says:

missing return statement
[javac] }
[javac] ^
[javac] 1 error

Actually the thing is that I cant change how the class is written.
I am posting the code. Any suggestions are welcome:

package net.astralpharma;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.Date;

public class Login extends ActionSupport {

public String execute()throws Exception

String x = getUsername();

String url = "jdbc:mysql://localhost:3306/";
String dbname="astraldb";
String driverName="org.gjt.mm.mysql.Driver";
String userName="root";
String password="root";
Connection con=null;
PreparedStatement stat =null;

System.out.println("Driver Loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/astraldb","root","root" );
System.out.println("Database is connected");
String query="Select password from logindet where username=?";
stat = con.prepareStatement(query);
stat.setString(1, x);
ResultSet rs = stat.executeQuery();

String pwd_db = rs.getString("password");
System.out.println("database_passwd" + pwd_db);
String pwd_fe = getPassword();
System.out.println("frontend_passwd" + pwd_fe);
return "SUCCESS";

return "ERROR";

catch(SQLException sqle)
System.out.println("Exception : " + sqle);
catch(Exception e)
System.out.println("Exception : " + e);

private String username = null;

public String getUsername() {
return username;

public void setUsername(String value) {
username = value;

private String password = null;

public String getPassword() {
return password;

public void setPassword(String value) {
password = value;

Prashant Singh
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

Prashant, please use code tags when you post a source code

I've corrected the return statement problem in your code. But the logic also looks wrong to me. If you are thinking that it will try to match the password with every password in the database, then I'm afraid that will not happen. What actually will happen is that it will match the password with only the first password in the database. If it matches, then it will return success otherwise it will return error. Although I'm sure that username would be unique in your database, but since you have used a while loop to check the password, so I am just warning you...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton

Joined: Sep 29, 2008
Posts: 12617

I'd also add that this code is antithetical to current Java (and S2) coding practices.

By embedding all that logic in the action itself things are more difficult to test, debug, and understand. YMMV, but I'd sure consider breaking it out into a service-makes unit testing both the service and the action *much* easier.
Prashant K. Singh

Joined: May 11, 2009
Posts: 18
thanks Ankit and thanks David.

You guys were bang on target
I agree. Here's the link: http://aspose.com/file-tools
subject: missing return statement {
It's not a secret anymore!