How to fix "missing return statement". error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Annie Soomro
    New Member
    • Feb 2011
    • 1

    How to fix "missing return statement". error?

    Getting "missing return statement" error for following code:

    Code:
    import java.sql.*;
    public class DatabaseManager{
      public static int add(String user,String password)throws Exception{
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con=DriverManager.getConnection("jdbc:odbc:userRecords");
        Statement st=con.createStatement();
        
    
        String query="insert into UserRecords(userName,pass) values('"+user+"','"+password+"')";
        System.out.println(query);
    
    
        st.close();
        con.close();
      }
    }
    Last edited by Niheel; Feb 5 '11, 08:11 PM. Reason: Please take the time to write a proper question.
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the method header
    Code:
    public static int add(String user,String password)throws Exception{
    states it returns an int result therefore the compiler expects a return statement. If you don't intend to rturn a result say the return type is void.

    Comment

    Working...