Here you can find the source of query(String sql)
public static ResultSet query(String sql)
//package com.java2s; //License from project: Apache License import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { private static Connection mConn = null; private static Statement mStmt = null; public static ResultSet query(String sql) { try {// w w w .j a v a 2 s . c om if (mStmt == null || mStmt.isClosed()) { openConnection(); } return mStmt.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); } return null; } private static void openConnection() { try { Class.forName("com.mysql.jdbc.Driver"); mConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/source_products", "root", "123"); mStmt = mConn.createStatement(); } catch (Exception e) { e.printStackTrace(); } } }