title: JDBC pass parameters to sql query
body: <p>I have</p>
  
  <pre><code>employee(id, name, company, salary);
  </code></pre>
  
  <p>Need to display data for given id</p>
  
  <pre><code>public static void Connect(String conString, String username, String password, int id) throws SQLException{
          try {
              Class.forName("com.mysql.jdbc.Driver");
              Connection conn = null;
              conn = DriverManager.getConnection(conString, username, password);
              String query = "select * from employee where id = " + id + "" ;
              ResultSet rs = null;
              Statement stmt = null;
              stmt = conn.createStatement();
              rs = stmt.executeQuery(query);
              while(rs.next()){
                  String name = rs.getString("name");
                  String company = rs.getString("company");
                  int salary = rs.getInt("salary");
                  System.out.println("Name: " + name + "\tCompany: " + company + "\tSalary: " + salary);
              }
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  </code></pre>
  
  <p>But here we are passing the id directly. How can we pass it like parametrized queries (like how we pass <code>?</code> during  <code>PreparedStatement</code>)</p>