Java SQL Query executeQuery(String sql, String[] parameters)

Here you can find the source of executeQuery(String sql, String[] parameters)

Description

execute Query

License

Apache License

Declaration

public static ResultSet executeQuery(String sql, String[] parameters) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    private static Connection ct = null;
    private static PreparedStatement ps = null;
    private static ResultSet rs = null;
    private static String url = "";
    private static String username = "";
    private static String password = "";

    public static ResultSet executeQuery(String sql, String[] parameters) {
        try {/*from w w w. j  a  v a2s .  co  m*/
            ct = getConnection();
            ps = ct.prepareStatement(sql);
            if (parameters != null) {
                for (int i = 0; i < parameters.length; i++) {
                    ps.setString(i + 1, parameters[i]);
                }
            }
            rs = ps.executeQuery();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
        return rs;
    }

    public static Connection getConnection() {
        try {
            ct = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ct;
    }
}

Related

  1. executeQuery(java.sql.Connection con, String select, Object pk)
  2. executeQuery(Statement state, String sql)
  3. ExecuteQuery(String command)
  4. executeQuery(String query)
  5. executeQuery(String sql, Connection conn, List param)
  6. executeQuery2(java.sql.Connection con, String select, Object... pk)
  7. executeRetrievalByIDQuery(PreparedStatement theStatement, int theID)
  8. executeSafeQuery( Connection conn, String sql)
  9. executeStatement(Connection connection, String query)

  10. HOME | Copyright © www.java2s.com 2016