Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

missing return statement {

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;

try
{
Class.forName(driverName);
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);
System.out.println(stat);
stat.setString(1, x);
ResultSet rs = stat.executeQuery();

while(rs.next())
{
String pwd_db = rs.getString("password");
System.out.println("database_passwd" + pwd_db);
String pwd_fe = getPassword();
System.out.println("frontend_passwd" + pwd_fe);
if(pwd_db.equals(pwd_fe))
{
return "SUCCESS";
}
else
{

return "ERROR";
}
}

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

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;
}
}
 
Sheriff
Posts: 9690
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Ankit and thanks David.

You guys were bang on target
 
reply
    Bookmark Topic Watch Topic
  • New Topic