Jaeksoft Pojodbc - Public Javadoc

The JAVA library which reconciles JDBC and POJO

See:
          Description

Packages
com.jaeksoft.pojodbc  
com.jaeksoft.pojodbc.connection  

 

The JAVA library which reconciles JDBC and POJO

Start working with POJO without rewriting all your JDBC application. Without any configuration file, without any annotation, use your native SQL request with JDBC and get POJO(s).

Sample code

Firstable, you need to create a ConnectionManager. A ConnectionManager is not a connection pool. Taking a jdbc url or a datasource, the ConnectionManager just provide new connection.

 JDBCConnection connectionManager = new JDBCConnection();
 connectionManager.setDriver("com.mysql.jdbc.Driver");
 connectionManager
                .setUrl("jdbc:mysql://localhost:3306/dbName?autoReconnect=true");
 

Now we can start working with our database. Pojodbc take care of database connection for you. You work with a transaction to obtain a list of Pojo.

 Transaction transaction = null;
 try {
    // Obtain a new transaction from the ConnectionManager
    transaction = connectionManager.getNewTransaction(false,
                              javax.sql.Connection.TRANSACTION_READ_COMMITTED);
    // Start a new Query
    Query query = transaction.prepare("SELECT * FROM MyTable WHERE status=?");
    query.getStatement().setString(1, "open");
    query.setFirstResult(0);
    query.setMaxResults(10);
    
    // Get the result
    List<MyPojo> myPojoList = query.getResultList(MyPojo.class));
    
    // do everything you need
    
  } finally {
    // Release the transaction
    if (transaction != null)
      transaction.close();
}

The only thing you have to do is to release the transaction. The best way to do that is to close the transaction in a finally clause. Pojodbc will release all Statement, ResultSet and Connection.

You dont have to maintain the transaction open to use your Pojo list.

License and copyright

Copyright (C) 2008 Emmanuel Keller / Jaeksoft

Jaeksoft Pojodbc is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Jaeksoft Pojodbc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Jaeksoft Pojodbc. If not, see http://www.gnu.org/licenses/.

Related Documentation

For overviews, tutorials, examples, guides, and tool documentation, please see: