title: Moving a database in netbeans to another computer
body: <p>I made a fairly small java program in netbeans, with the database saved in the scr folder under database/mainUserData, On my main pc, if i export it to a .jar folder, It works, If i copy all the data in the folder (70mb's worth) to another pc, it can't find the database any more, I made sure to add code that always uses the current directory in the jar folder as a url to the database, this is the connection code:</p>
  
  <pre><code>myconObj = DriverManager.getConnection("jdbc:derby://localhost:1527/MainUserData", "jacovanstryp", "Password1234");
  </code></pre>
  
  <p>Why is it when i move it to another computer (The whole file, it no longer knows where the database is?</p>
  
  <p>What I have Tried:</p>
  
  <pre><code>URL url = this.getClass().getResource("/com/vanstryp/res/Database/MainUserData"); // This is the same directory as where the .jar is located
  </code></pre>
  
  <p>This just returns Null.</p>
  
  <p>This is the top Error code it returns</p>
  
  <pre><code>java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1,527 with message Connection refused: connect.
  </code></pre>
  
  <p>This is the code for the method I used</p>
  
  <pre><code>  public boolean checkLogin(String username, String password) {
      try {
          Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
          //This code will connect the database to the java program
          //Information to connect database obtained from --&gt;  https://www.youtube.com/watch?v=c7RZV4VLv3s
          Connection myconObj = null; //allows to connect to database
          Statement mystatObj = null; // create statement (Execute queries)
          ResultSet myresObj = null; // get result
          ResultSetMetaData mymeta = null;
  
          try {
  
              String query = "select * from JACOVANSTRYP.MAINUSERDATA";
              URL databaseLocation = this.getClass().getResource("/com/vanstryp/database/MainUserData/");
  
              myconObj = DriverManager.getConnection("jdbc:derby:/" + databaseLocation, "jacovanstryp", "Eduplex1234");
              mystatObj = myconObj.createStatement();
              myresObj = mystatObj.executeQuery(query);
              mymeta = myresObj.getMetaData();
              int colomnNo = mymeta.getColumnCount();
  
              while (myresObj.next()) {
                  String dbUsername = myresObj.getString("Username");
                  String dbPassword = myresObj.getString("Password");
                  System.out.println();
                  if (username.equalsIgnoreCase(dbUsername) &amp;&amp; password.equals(dbPassword)) {
  
                      PrintWriter activeUser = new PrintWriter(new FileWriter("activeUser.db"));
                      activeUser.println(dbUsername);
                      activeUser.close();
                      return true;
  
                  }
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return false;
      } catch
  
   (ClassNotFoundException ex) {
              Logger.getLogger(commonMethods.class.getName()).log(Level.SEVERE, null, ex);
          }
          return false;
  }
  </code></pre>