|
@@ -12,7 +12,7 @@ public class DataBaseConnector {
|
|
|
|
|
|
public void initConnection(ConnectionParams connectionParams) {
|
|
|
|
|
|
- System.out.println("Trying to connect with params:\n\thost:\t\t" + connectionParams.host()
|
|
|
+ System.out.println("Connecting with params:\n\thost:\t\t" + connectionParams.host()
|
|
|
+ "\n\tuser:\t\t" + connectionParams.user()
|
|
|
+ "\n\tpassword:\t" + connectionParams.password());
|
|
|
|
|
@@ -39,7 +39,31 @@ public class DataBaseConnector {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public boolean initilized(){
|
|
|
+ public Boolean tryConnection(ConnectionParams connectionParams) {
|
|
|
+ System.out.println("Trying to connect with params:\n\thost:\t\t" + connectionParams.host()
|
|
|
+ + "\n\tuser:\t\t" + connectionParams.user()
|
|
|
+ + "\n\tpassword:\t" + connectionParams.password());
|
|
|
+
|
|
|
+ try {
|
|
|
+ String url = "jdbc:mysql://" + connectionParams.host();
|
|
|
+ DriverManager.setLoginTimeout(2);
|
|
|
+ DriverManager.getConnection(url, connectionParams.user(), connectionParams.password());
|
|
|
+ System.out.println("Successful");
|
|
|
+ return true;
|
|
|
+ } catch (SQLException ex) {
|
|
|
+ //exception
|
|
|
+ if (ex.getMessage().contains("Communications link failure")) {
|
|
|
+ System.out.println(ex.getMessage());
|
|
|
+ } else if (ex.getMessage().contains("Access denied")) {
|
|
|
+ System.out.println(ex.getMessage());
|
|
|
+ } else {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean initialized(){
|
|
|
return !initilizeErr;
|
|
|
}
|
|
|
|