Java SQL ResultSet Read getResultSet(Connection connection, String query)

Here you can find the source of getResultSet(Connection connection, String query)

Description

to get a result set of a query

License

Apache License

Parameter

Parameter Description
connection connection object
query custom query

Exception

Parameter Description
SQLException throws an exception if an error occurs

Return

a result set of custom query

Declaration

public static ResultSet getResultSet(Connection connection, String query) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**/* w w w  . j a  v  a2  s .  c  o m*/
     * to get a result set of a query
     * 
     * @param connection
     *            connection object
     * @param query
     *            custom query
     * @return a result set of custom query
     * @throws SQLException
     *             throws an exception if an error occurs
     */
    public static ResultSet getResultSet(Connection connection, String query) throws SQLException {
        ResultSet rs;
        PreparedStatement st = connection.prepareStatement(query);
        rs = st.executeQuery();
        return rs;
    }
}

Related

  1. getResultByMap(ResultSet rs)
  2. getResults(ResultSet result)
  3. getResultsAsMap(ResultSet rs)
  4. getResultSet(Connection c, String query)
  5. getResultSet(Connection conn, String query)
  6. getResultSet(String sql)
  7. getResultSetColnumNames(ResultSet rs)
  8. getResultSetColumns(ResultSet rs)
  9. getResultSetDateValue(ResultSet rs, String sColumnName)