Recently I am making a small system in which I've 3 packages using Ms Access as database
1)Classes----> Based on OOP concepts
2)GUI------> The Jform + .java files
3)Images---->Just some icons i made
I've made a DBConnection
class in the Classes package(using UCanAccess
).
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);
}
} }
Next I've made a Loger
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 DBConnection
Class?This is the code for Loger
class
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!";
} }
In short I am stuck please help because I have to make more classes (OOP
based)and just make methods in such classes to execute different queries.