Ignore:
Timestamp:
2021-02-18T17:16:49+13:00 (3 years ago)
Author:
su41
Message:

Added another error message handler for incorrect database name.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/tipple-bridge/trunk/src/src/main/java/sqlCli.java

    r34899 r34900  
    1313/*
    1414TODO:
    15 for the CLI:
    16 - Error handling
    17 - Subcommands?
    1815
    1916 */
    2017
    21 //-u su41Tipple -p --port 3306 --dbname tippleTest1
     18//-u su41Tipple -p --port 3306 --dbname koicarp_test
    2219//@/home/su41/configFileTest
    2320
     
    2724@Command (name="sqlCli", description = "Arguments for database connection", mixinStandardHelpOptions = true)
    2825public class sqlCli implements Callable<Integer> {
     26
    2927    //our cli arguments
    30 
    3128    @Option(names = {"-u", "--user"}, description = "The user name",
    3229            required = true)
     
    3532    //interactive allows the user to omit the argument value and instead enter it as a prompt
    3633    /*
    37     NOTE: if you are running an interactive option on an IDE, most likely will be using something
    38     like the javaw.exe library which tries to mimic the terminal.
     34    NOTE: if you are running an interactive option on an IDE, most likely the IDE will be using
     35    the javaw.exe library which tries to mimic the terminal.
    3936    The point is that interactive option would usually make whatever you enter hidden (it doesn't
    4037    echo back) but on the IDE it will echo back.
     
    6259        this parameter can be read in at any point on the options line.
    6360        but that's only because it's the only parameter at the moment.
    64         If we add more parameters, will either have to put them next to each other
    65         OR add in indexes
     61        If we add more parameters, will have to start indexing
    6662        https://picocli.info/quick-guide.html#_options_and_parameters
    6763         */
     
    9389        Connection conn;
    9490        Statement stmt;
     91        //return status for code to send back to commandLine.execute
    9592        int returnStatus = 0;
    9693       // String dbUrl = "jdbc:mysql://localhost:" + port +"/"+ dbName;
     
    103100    System.out.println("Saving output to:");
    104101    System.out.println("  " + fileName);
    105    
     102
    106103        try (FileWriter file = new FileWriter(fileName)){
    107104            //register the jdbc driver
     
    200197        }
    201198        catch(SQLException sqlError){
     199            // looking at the sql error code is good for debugging.
     200            // can ref: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-error-sqlstates.html
     201            // to see what they're for
     202
    202203           // System.out.println("MySQL error code: " + sqlError.getErrorCode());
     204
     205
    203206            //prints out the error message from sql, then check to see which error code
    204207            // came back and what the code matches.
     
    210213               System.out.println("    -'Username'");
    211214               System.out.println("    -'Password' ");
    212                System.out.println("    -'Database name' ");
     215            }
     216
     217            if(sqlError.getErrorCode() == MysqlErrorNumbers.ER_DBACCESS_DENIED_ERROR){
     218                System.out.println("Error with database credentials. Double check your: ");
     219                System.out.println("    -'Database name' ");
    213220            }
    214221           returnStatus = 1;
Note: See TracChangeset for help on using the changeset viewer.