Results 1 to 3 of 3
  1. #1
    brian is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default missing return statement

    both methods are giving me a missing return statement and I can't figure out why.
    Java Code:
    import java.sql.*;
    
    public class practice1 {
        String driver = "com.mysql.jdbc.Driver";
        public static void main(String []args){
            practice1 practice = new practice1();
            practice.addUser("Brian1", "asddsg");
        }
    
    
    public boolean addUser(String UserName, String Password){
    
    Connection conn = null;
    Statement stmt = null;
    
    String username = UserName;
    String password = Password;
    try{
    Class.forName(driver).newInstance();
    String connURL = "jdbc.mysql://localhost/prog38081";
    String dbUsername = "root";
    String dbPassword = "";
    
    conn = DriverManager.getConnection(connURL, dbUsername, dbPassword);
    
    stmt = conn.createStatement();
    
    String sql = "Insert into Login (username, password)" + " Values ('" + username + "', '" + password + "')"; 
    int rows = stmt.executeUpdate(sql);
    
    if (rows > 0){
        return true;
    }else{
        return false;
    }
    
    
    }catch(ClassNotFoundException cnf){
       System.out.println("class not found");
        return false;
    }catch(InstantiationException ie){
         System.out.println("instantiation");
        return false;
    }catch(IllegalAccessException iae){
         System.out.println("Illegal access");
        return false;
    }catch(SQLException sql){
         System.out.println("sql");
        
    }finally{
        try{
            if(stmt != null){
                stmt.close();
            }
            if(conn != null){
            conn.close();
        }
            
        }catch(Exception ex){
        }
        
    
    }
          
    }
        public boolean delUser(String UserName, String Password){
            
            Connection conn = null;
            Statement stmt = null;
            
            String username = UserName;
            String password = Password;
          try{  
            Class.forName(driver).newInstance();
            
            String connURL = "jbdc.mysql://localhost/prog38081";
           String dbusername = "root";
           String dbpassword = "";
            conn = DriverManager.getConnection(connURL, dbusername, dbpassword);
            stmt = conn.createStatement();
            
            String sql = "delete from Login " + "where username =  '" + username +  "' and password = '" + password + "'";
            
            int rows = stmt.executeUpdate(sql);
            
            if (rows > 0) {
    
    return true;
    
    } else {
    
    return false;
    
    }
            
            
        
    }catch(ClassNotFoundException cnf){
        
    }catch(InstantiationException ins){
        
    }catch(IllegalAccessException iae){
        
    }catch(SQLException sql){
        
    }finally{
        try{
            if(stmt != null){
                stmt.close();
            }
            if(conn != null){
            conn.close();
        }
            
        }catch(Exception ex){
        }
    }
        }
    }
    Last edited by JosAH; 05-27-2013 at 06:50 PM. Reason: added [code] ... [/code] tags

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,412
    Rep Power
    5

    Default Re: missing return statement

    Let's say you catch an exception, process it, and then continue. What do you return?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    brian is offline Member
    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Default Re: missing return statement

    thanks, I figured it out. I missed a couple return statements on the exceptions.

Similar Threads

  1. missing return statement need help!!
    By windywong in forum New To Java
    Replies: 3
    Last Post: 03-27-2013, 01:30 PM
  2. Missing return statement
    By Aenohe in forum New To Java
    Replies: 8
    Last Post: 03-07-2012, 01:03 PM
  3. Missing return statement... but there is one
    By Eleeist in forum New To Java
    Replies: 4
    Last Post: 02-05-2012, 07:24 PM
  4. Missing Return statement =[
    By avirunes in forum New To Java
    Replies: 6
    Last Post: 02-12-2011, 10:34 AM
  5. missing return statement
    By bayan in forum New To Java
    Replies: 6
    Last Post: 04-26-2010, 03:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •