Here you can find the source of execute(final String url, final String username, final String password, final String sql, final Consumer
Parameter | Description |
---|---|
conf | a parameter |
sql | a parameter |
consumer | a parameter |
Parameter | Description |
---|---|
SQLException | an exception |
public static void execute(final String url, final String username, final String password, final String sql, final Consumer<ResultSet> consumer) throws SQLException
//package com.java2s; /* $Id: d9f0c935a858f9b9afe1ecc368d00381180da56b $ * //from w w w.j av a 2 s .co m * @license * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.function.Consumer; public class Main { /** * @param conf * @param sql * @param consumer * @throws SQLException */ public static void execute(final String url, final String username, final String password, final String sql, final Consumer<ResultSet> consumer) throws SQLException { // FIXME use connection pool with time-outs? try (final Connection conn = DriverManager.getConnection(url, username, password); final Statement stmt = conn.createStatement(); final ResultSet rs = stmt.executeQuery(sql);) { consumer.accept(rs); } } }