Results 1 to 3 of 3
Thread: missing return statement
- 05-27-2013, 06:45 PM #1
Member
- Join Date
- May 2013
- Posts
- 2
- Rep Power
- 0
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
- 05-27-2013, 06:55 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,174
- Rep Power
- 12
Re: missing return statement
Let's say you catch an exception, process it, and then continue. What do you return?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 05-27-2013, 08:02 PM #3
Member
- Join Date
- May 2013
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
missing return statement need help!!
By windywong in forum New To JavaReplies: 3Last Post: 03-27-2013, 01:30 PM -
Missing return statement
By Aenohe in forum New To JavaReplies: 8Last Post: 03-07-2012, 01:03 PM -
Missing return statement... but there is one
By Eleeist in forum New To JavaReplies: 4Last Post: 02-05-2012, 07:24 PM -
Missing Return statement =[
By avirunes in forum New To JavaReplies: 6Last Post: 02-12-2011, 10:34 AM -
missing return statement
By bayan in forum New To JavaReplies: 6Last Post: 04-26-2010, 03:15 PM
Bookmarks