title: SQL Query with 2 Parameter in a GetRequest
body: <p>I have a question. With a GetRequest I want a SQL query where I query 2 parameters.
  The Sql query is </p>
  
  <p><code>SELECT * FROM templates WHERE user_name=user_name AND template_id=template_id</code></p>
  
  <p><strong>User_name and template_id</strong> should be taken over the <strong>GetRequest</strong>.</p>
  
  <p>I want to return everything where the username is user_name and the template_id = template_id.My first try looks like this</p>
  
  <pre><code>public class SelectTemplate {
      public void SelectExactTemplate(String user_name, int template_id)
       {
           try{
              Connection conn=this.connect();
              Statement stmt=conn.createStatement();
              ResultSet rs;
              rs = stmt.executeQuery("SELECT * FROM templates WHERE user_name=user_name AND template_id=template_id");
              while ( rs.next() ) 
              {
  
                  rs.getString(user_name);
                  rs.getInt(template_id);
  
              }
              conn.close();
              }
              catch (SQLException e)
              {
                  System.out.println(e.getMessage());
              }
       }
       private Connection connect() {
              // SQLite connection string
              String url = "xxxxxxx";
              Connection conn = null;
              try {
                  conn = DriverManager.getConnection(url,"xxxxx","xxxxxxx");
              } catch (SQLException e) {
                  System.out.println(e.getMessage());
              }
              return conn;
          }
  </code></pre>
  
  <p>This is the class in which I connect to the database and start the query.
  My GetRequest</p>
  
  <pre><code>    @GetMapping("/templates/user_name/template_id")
      public Template retrieveUser(@RequestBody Template template)
      {
          SelectTemplate app=new SelectTemplate();
          String user_name=template.getUserName();
          int template_id=template.getTemplateId();
          app.SelectExactTemplate(user_name, template_id);
  
          return template;
      }
  </code></pre>
  
  <p>And my Repository</p>
  
  <pre><code>public interface TemplateRepository extends JpaRepository&lt;Template, Integer&gt;{
  
  }
  </code></pre>
  
  <p>when I start a GetRequest at POSTMAN, I get an error "<strong>Not Found</strong>" </p>
  
  <p>Can someone tell me what I'm doing wrong or how to better solve the problem?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    public class SelectTemplate {   
         @Autowired 
         private TemplateRepository templateRepository;
         public Template SelectExactTemplate(String user_name, int template_id) {
             return templateRepository.findByIdAndUserName(template_id, user_name);
         }
  </code></pre>
  
  <p>And the Repository</p>
  
  <pre><code>public interface TemplateRepository extends JpaRepository&lt;Template, Integer&gt;{
  
      Template findByIdAndUserName(int template_id, String user_name);
  
      Template findByUserName(String user_name);
  
  
  }
  </code></pre>
  
  <p>I also tried the query once for just username. I still get the "NOT FOUND" error.</p>
  
  <pre><code>    @GetMapping("/templates/user_name")
      public Template retrieveTemplateByUsername(String user_name)
      {
           return templateRepository.findByUserName( user_name);  
      }
  </code></pre>
  
  <p><strong>UPDATE 2</strong></p>
  
  <pre><code>@GetMapping("/templates/{user_name}")
      public List&lt;Template&gt; retrieveTemplateByUsername(@PathVariable("user_name") String user_name)
      {
            return templateRepository.findByUserName(user_name);  
      }
  </code></pre>
  
  <p>That works now. I had to change something in the Repository</p>
  
  <pre><code>List&lt;Template&gt; findByUserName(String user_name);
  </code></pre>
  
  <p>But if i want to find 1 template selected by template_id und user_name, i got an empty value</p>
  
  <pre><code>@GetMapping("/templates/{user_name}/{template_id}")
      public Template retrieveTemplate(@PathVariable("user_name") String user_name,@PathVariable("template_id") int template_id)
      {
          return templateRepository.findByIdAndUserName(template_id, user_name);
  
      }
  </code></pre>
  
  <p><strong>UPDATE 3</strong>
  Problem solved. The Query looked for the id and not for the template_id </p>
  
  <p>THX A LOT</p>