Create a class to connect to any database using jdbc

前端 未结 4 1234
长发绾君心
长发绾君心 2020-12-15 02:01

I am trying to design a Java swing application. I want to experiment and use an MVC type of architecture whereby my UI is separated from the actual logic to access data and

4条回答
  •  渐次进展
    2020-12-15 02:37

    You can either use fancier stuff like Hibernate or if your database usage is simple then you can try Commons DbUtils

    Ceremonial connection code

    String db = "jdbc:h2:mem:;INIT=runscript from 'classpath:/prototypeeop.sql'"; 
    //for H2 in-memory database:
    Connection DriverManager.getConnection(db);
    
    

    Remember the core classes and interfaces in Commons DbUtils are QueryRunner and ResultSetHandler.

提交回复
热议问题