Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a need to put the database connection and close methods to AspectJ class. Currently my add method looks like below:
Java
public void addBookDetails(String name, String author, String publisher, int year, int price){

    Connection conn=null;
    DBConnection DBConn=new DBConnection();
    try {
        conn=DBConnection.createConnection();
        Statement statement=conn.createStatement();
        System.out.println("INSERT INTO Books " + "VALUES ('"+name+"', '"+author+"', '"+publisher+"', '"+year+"', '"+price+"')");
        statement.executeUpdate("INSERT INTO Books " + "VALUES ('"+name+"', '"+author+"', '"+publisher+"', '"+year+"', '"+price+"')");
        DBConn.closeConnection();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}


How can I get this createConnection and closeConnection methods into as Aspect class? Because they dont belong to the scope of addBookDetails. Please advice. I dont understand how to use the "conn" object if I move this method. Because it will be needed for CreateStatement method in this class.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900