Changeset 34896
- Timestamp:
- 2021-02-18T11:30:17+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/tipple-bridge/trunk/src/src/main/java/sqlCli.java
r34894 r34896 1 import com.google.gson.JsonArray;2 1 import com.mysql.cj.exceptions.MysqlErrorNumbers; 3 2 import picocli.CommandLine; 4 3 import picocli.CommandLine.Command; 5 4 import picocli.CommandLine.Option; 5 import picocli.CommandLine.Parameters; 6 6 7 7 import java.sql.*; … … 44 44 45 45 @Option(names = {"--port"}, description="Port number", defaultValue="3306") 46 int port No;46 int port; 47 47 48 48 @Option(names = {"--dbname"}, description="Name of the database", defaultValue="koicarp_test") … … 54 54 String projectID; 55 55 56 //defaultValue in case the user doesn't enter in an option for it 57 //make this option so that the program can read in without typing in --filename everytime 58 //read this option in last 59 @Option(names = {"--fileName"}, description = "Name of output JSON file", 60 required = true) 61 String fileName; 56 57 /* 58 this parameter can be read in at any point on the options line. 59 but that's only because it's the only parameter at the moment. 60 If we add more parameters, will either have to put them next to each other 61 OR add in indexes 62 https://picocli.info/quick-guide.html#_options_and_parameters 63 */ 64 @Parameters(description = "Name of the output JSON file. E.g. yourFileName.json") 65 String jsonOutputFile; 62 66 63 67 @Option(names = {"--host"}, description = "Type of host e.g. localhost ", … … 65 69 String host; 66 70 67 68 public void run() { 69 databaseConnect(userName, password, portNo, dbName, projectID, fileName, host); 71 public void run(){ 72 //if it doesn't end with ... 73 if(!jsonOutputFile.endsWith(".json")){ 74 System.out.println("Invalid file format."); 75 System.out.println("The file to save the output to must be a .json file."); 76 //exit code other than 0 means it's not fine. 77 System.exit(1); 78 } 79 //else we're good to go. 80 databaseConnect(userName, password, port, dbName, projectID, jsonOutputFile, host); 70 81 } 71 82 … … 144 155 for every data type, 145 156 if a data type changes in the database that's probably fine, but 146 if a new data type is sent in, the code may not handle it157 if a new data type is sent in, we'll have update the statements 147 158 */ 148 159 /* … … 192 203 } 193 204 catch(SQLException sqlError){ 194 System.out.println("MySQL error code: " + sqlError.getErrorCode()); 205 // System.out.println("MySQL error code: " + sqlError.getErrorCode()); 206 //prints out the error message from sql, then check to see which error code 207 // came back and what the code matches. 208 // if it's access denied, usually something to do with username, password or db name 195 209 System.out.println(sqlError.getMessage()); 196 //System.out.println(MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR); 210 197 211 if(sqlError.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR){ 198 212 System.out.println("Error with database credentials. Double check your: "); … … 201 215 System.out.println(" -'Database name' "); 202 216 } 203 sqlError.printStackTrace();204 217 205 218 }
Note:
See TracChangeset
for help on using the changeset viewer.