Java SQL Query query(Connection conn, String sql)

Here you can find the source of query(Connection conn, String sql)

Description

query the specified SQL in database.

License

Open Source License

Parameter

Parameter Description
conn the connection established to the database
sql the SQL statement to be executed

Exception

Parameter Description
SQLException if any error occurs while executing the SQL

Return

the result set

Declaration

public static ResultSet query(Connection conn, String sql) throws SQLException 

Method Source Code

//package com.java2s;

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 a 2  s  .  co  m
     * query the specified SQL in database.
     *
     * @param conn the connection established to the database
     * @param sql the SQL statement to be executed
     * @return the result set
     * @throws SQLException if any error occurs while executing the SQL
     */
    public static ResultSet query(Connection conn, String sql) throws SQLException {
        PreparedStatement preparedStatement = conn.prepareStatement(sql);
        return preparedStatement.executeQuery();
    }
}

Related

  1. executeRetrievalByIDQuery(PreparedStatement theStatement, int theID)
  2. executeSafeQuery( Connection conn, String sql)
  3. executeStatement(Connection connection, String query)
  4. getSqlQuery(Statement statement, Object[] args)
  5. getStatement(Connection con, String query, Object... bits)
  6. query(Connection conn, String sql, Object[] params, Class beanClass)
  7. query(Connection connection, String sql, boolean isClose, Object... params)
  8. queryForList(Connection conn, String sql, int limit)
  9. queryObjectList(Connection con, String sql, Class objClass)