All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jaeksoft.pojodbc.overview.html Maven / Gradle / Ivy

Go to download

OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface, the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and Linux/Unix/BSD.

The newest version!






	

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 have 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");
 connectionManager.setUsername("user");
 connectionManager.setPassword("pass");
 

Now we can start working with our database. Pojodbc take care of the database connection. The following code shows how to obtain a list of Pojo.

 Transaction transaction = null;
 try {
    // Obtain a new transaction from the ConnectionManager
    transaction = connectionManager.getNewTransaction(false,
                              java.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-2015 OpenSearchServer Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific

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.

OpenSearchServer 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.

Related Documentation

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy