simple jdbc wrapper

前端 未结 8 944
青春惊慌失措
青春惊慌失措 2021-01-01 21:35

To implement data access code in our application we need some framework to wrap around jdbc (ORM is not our choice, because of scalability).

The coolest framework I

相关标签:
8条回答
  • 2021-01-01 22:16

    Spring-JDBC is fantastic. Consider that for an open source project like Spring the down side of external dependency is minimized. You can adopt the most stable version of Spring that satisfies your JDBC abstraction requirements and you know that you'll always be able to modify the source code yourselves if you ever run into an issue -- without depending on an external party. You can also examine the implementation for any security concerns that your organization might have with code written by an external party.

    0 讨论(0)
  • 2021-01-01 22:20

    Jedoo

    There is a wrapper class called Jedoo out there that uses database connection pooling and a singleton pattern to access it as a shared variable. It has plenty of functions to run queries fast.

    Usage

    To use it you should add it to your project and load its singleton in a java class:

    import static com.pwwiur.util.database.Jedoo.database;
    

    And using it is pretty easy as well:

    if(database.count("users") < 100) {
        long id = database.insert("users", new Object[][]{
            {"name", "Amir"},
            {"username", "amirfo"}
        });
        
        database.setString("users", "name", "Amir Forsati", id);
    
        try(ResultSetHandler rsh = database.all("users")) {
             while(rsh.next()) {
                 System.out.println("User ID:" + rsh.getLong("id"));
                 System.out.println("User Name:" + rsh.getString("name"));
             }
        }
    }
    

    There are also some useful functions that you can find in the documentation linked above.

    0 讨论(0)
提交回复
热议问题