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

play.db.helper.JdbcHelper Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.db.helper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import play.db.DB;

public class JdbcHelper {

    private JdbcHelper() {
    }

    public static ResultSet execute(String sql, Object ... params) throws SQLException {
        PreparedStatement pst = DB.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        int index = 0;
        for (Object param : params) {
            pst.setObject(++index, param);
        }
        return pst.executeQuery();
    }

    public static ResultSet executeList(String sql, List params) throws SQLException {
        PreparedStatement pst = DB.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        int index = 0;
        for (Object param : params) {
            pst.setObject(++index, param);
        }
        return pst.executeQuery();
    }

    public static ResultSet execute(SqlQuery query) throws SQLException {
        return executeList(query.toString(), query.getParams());
    }

}