Here you can find the source of executeSQL(Connection conn, String sql)
Parameter | Description |
---|---|
conn | the <code>Connection</code> object to use |
sql | the SQL statement to execute |
ResultSet
resulting from running the query
public static ResultSet executeSQL(Connection conn, String sql) throws SQLException
//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; } }