Java SQL Execute executeSQL(Connection conn, String sql)

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

Description

Creates a SQL Statement and execute the statement using JDBC executeQuery method.

License

Open Source License

Parameter

Parameter Description
conn the <code>Connection</code> object to use
sql the SQL statement to execute

Return

The ResultSet resulting from running the query

Declaration

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

Method Source Code


//package com.java2s;
/*//  w ww.  ja  va  2  s  .  co  m
* Copyright (c) 2005. IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     IBM Corporation - initial API and implementation
*/

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    /**
     * Creates a SQL Statement and execute the statement using JDBC executeQuery
     * method. This method uses a Statement object to execute the query. It does
     * not close the Statement exlicitly because the ResultSet object will be
     * closed if the Statement is closed.
     * 
     * @param conn the <code>Connection</code> object to use
     * @param sql the SQL statement to execute
     * @return The <code>ResultSet</code> resulting from running the query
     */
    public static ResultSet executeSQL(Connection conn, String sql) throws SQLException {
        ResultSet result = null;
        Statement statement = null;
        try {
            statement = conn.createStatement();
            result = statement.executeQuery(sql);
        } catch (SQLException ex) {
            if (statement != null)
                statement.close();
            throw ex;
        }
        return result;
    }
}

Related

  1. executeResource(Connection con, String resource)
  2. executeSetArgs(PreparedStatement stmt, Object... args)
  3. executeShutDownForHSQL(java.sql.Connection connection)
  4. executeSP(Connection conn, String spName, Object... parameters)
  5. executeSql(Connection conn, String sql)
  6. executeSql(Connection conn, String sql)
  7. executeSQL(Connection connection, String file)
  8. executeSQL(Connection session, String sql, Object... params)
  9. executeSqlAutoCommit(Connection connection, String sql)