/** Tries to connect to the database with given credentials */
 private boolean tryConnect() throws MsfException {
   Map status = (Map) rpcConn.execute("db.status");
   if (status.containsKey("db")) return true; // already connected
   HashMap opts = new HashMap();
   addNonempty("host", hostField, opts);
   addNonempty("port", portField, opts);
   addNonempty("username", usernameField, opts);
   addNonempty("password", passwordField, opts);
   addNonempty("database", dbNameField, opts);
   opts.put("driver", typeSpinner.getValue().toString());
   props.put("dbdriver", typeSpinner.getValue().toString());
   Map res = (Map) rpcConn.execute("db.connect", opts);
   return "success".equals(res.get("result"));
 } // GEN-LAST:event_connectButtonActionPerformed
Example #2
0
 /**
  * Creates an RPC connection of the appropriate type and connection details
  *
  * @param type RPC type
  * @param username
  * @param password
  * @param host IP address or hostname of RPC server
  * @param port Port RPC server is operating on
  * @param ssl Whether SSL is to be used
  * @return A new RPC connection
  * @throws MsfException
  */
 public static RpcConnection getConn(
     String username, char[] password, String host, int port, boolean ssl) throws MsfException {
   RpcConnection conn = new MsgRpc();
   conn.setup(username, password, host, port, ssl);
   return conn;
 }