Here you can find the source of query(Connection conn, String sql)
Parameter | Description |
---|---|
conn | the connection established to the database |
sql | the SQL statement to be executed |
Parameter | Description |
---|---|
SQLException | if any error occurs while executing the SQL |
public static ResultSet query(Connection conn, String sql) throws SQLException
//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(); } }