title: How to call method from a database connection class
body: <p>Recently I am making a small system in which I've 3 packages using Ms Access as database</p>
  
  <p>1)Classes----> Based on OOP concepts</p>
  
  <p>2)GUI------> The Jform + .java files</p>
  
  <p>3)Images---->Just some icons i made</p>
  
  <p>I've made a <code>DBConnection</code> class in the Classes package(using <code>UCanAccess</code>).</p>
  
  <pre><code>import java.sql.*;
  public class DBConnection {
  public DBConnection() {
  
      try {
          String driver = "net.ucanaccess.jdbc.UcanaccessDriver";
          Class.forName(driver);
          String dbPath = "jdbc:ucanaccess://E:\\University Docs\\BSCS 3A\\Object Oriented Programming\\LibraryManagementSystem\\LMSDatabase.accdb";
          Connection con = DriverManager.getConnection(dbPath);
          Statement st = con.createStatement();
          System.out.println("Connection Succesful");
          ResultSet rsObject = st.executeQuery(dbPath);
          con.close();
      } catch (Exception sqlEx) {
          System.out.println(sqlEx);
  }
  }                    }
  </code></pre>
  
  <p>Next I've made a <code>Loger</code> class for creating a login and logout methods in the same package.The problem is that how do I execute my query in this class by using the <code>DBConnection</code> Class?This is the code for <code>Loger</code> class</p>
  
  <pre><code>public class Loger { 
  
  private String lname, lpassword;
  
  public Loger(String lname, String lpassword) {
      this.lname = lname;
      this.lpassword = lpassword;
      //Login();
  }
  
  
  public String Login()throws ClassNotFoundException,SQLException
  {
      DBConnection d1 = new DBConnection();
      String query1 = "SELECT * FROM Admintable WHERE Admin_ID = ' "+this.lname+" AND Admin_Password = '"+this.lpassword+"'" ;
  
      return "Success!";
  
  }                   }
  </code></pre>
  
  <p>In short I am stuck please help because I have to make more classes (<code>OOP</code> based)and just make methods in such classes to execute different queries.  </p>