I am developing a very simple Java application, through which to take files from a folder, obtain information from them and save them in the database.
The app is launched from the command line, and I need to pass the following parameters: file_path, db_name, db_user, db_host, db_user_psw.
When I run the check to see if all the parameters have been passed, in case a parameter is missing, I get an index out of bound exception, correctly according to java. My need is to bypass this exception and display a string indicating an error message.
For example, if all parameters except db_user_psw are entered, instead of getting index of bound exception I would like the message "You must enter the password to access the db!".
My idea is to pre-assign the args to null, and once the script is run check if they are null or not. Is it possible to do this in java? I accept any advice or suggestion
- My code:
if(args[0] == null ){ System.out.println("Insert a valid Path!"); System.exit(0); }
if(args[1] == null ){ System.out.println("Insert the DB IP!"); System.exit(0);}
if(args[2] == null ){ System.out.println("Insert a DB name!"); System.exit(0);}
if(args[3] == null ){ System.out.println("Insert a DB Username!"); System.exit(0);}
if(args[4] == null ){ System.out.println("Insert User DB Password!"); System.exit(0);}