Changeset 34900 for gs2-extensions/tipple-bridge
- Timestamp:
- 2021-02-18T17:16:49+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/tipple-bridge/trunk/src/src/main/java/sqlCli.java
r34899 r34900 13 13 /* 14 14 TODO: 15 for the CLI:16 - Error handling17 - Subcommands?18 15 19 16 */ 20 17 21 //-u su41Tipple -p --port 3306 --dbname tippleTest118 //-u su41Tipple -p --port 3306 --dbname koicarp_test 22 19 //@/home/su41/configFileTest 23 20 … … 27 24 @Command (name="sqlCli", description = "Arguments for database connection", mixinStandardHelpOptions = true) 28 25 public class sqlCli implements Callable<Integer> { 26 29 27 //our cli arguments 30 31 28 @Option(names = {"-u", "--user"}, description = "The user name", 32 29 required = true) … … 35 32 //interactive allows the user to omit the argument value and instead enter it as a prompt 36 33 /* 37 NOTE: if you are running an interactive option on an IDE, most likely will be using something38 likethe 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. 39 36 The point is that interactive option would usually make whatever you enter hidden (it doesn't 40 37 echo back) but on the IDE it will echo back. … … 62 59 this parameter can be read in at any point on the options line. 63 60 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 66 62 https://picocli.info/quick-guide.html#_options_and_parameters 67 63 */ … … 93 89 Connection conn; 94 90 Statement stmt; 91 //return status for code to send back to commandLine.execute 95 92 int returnStatus = 0; 96 93 // String dbUrl = "jdbc:mysql://localhost:" + port +"/"+ dbName; … … 103 100 System.out.println("Saving output to:"); 104 101 System.out.println(" " + fileName); 105 102 106 103 try (FileWriter file = new FileWriter(fileName)){ 107 104 //register the jdbc driver … … 200 197 } 201 198 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 202 203 // System.out.println("MySQL error code: " + sqlError.getErrorCode()); 204 205 203 206 //prints out the error message from sql, then check to see which error code 204 207 // came back and what the code matches. … … 210 213 System.out.println(" -'Username'"); 211 214 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' "); 213 220 } 214 221 returnStatus = 1;
Note:
See TracChangeset
for help on using the changeset viewer.