title: ms access database with java
body: <p>I am creating a java program, with which I am editing into a Microsoft Access Database. I have a certain case, in which I need to search if a certain record already exists in my table, if it does, I want to update it, and if not, I want to create it from scratch. </p>
  
  <p>I have found this piece of code:</p>
  
  <pre><code>IF EXISTS (SELECT * FROM USERS WHERE USERID=@UID) select 1 else select 
  </code></pre>
  
  <p>This code gives me an error, saying that a SELECT, UPDATE or DELETE statement was expected.</p>
  
  <p>In a code that I have tried my self, I have done the following:</p>
  
  <pre><code>try{
              s = con.createStatement();
              s.executeQuery("SELECT * FROM table WHERE date='" + today + "'");
              rset = s.getResultSet();    
  
              if (rset.getString("date") == null){
  
                  s = con.createStatement();     
                  s.executeUpdate("INSERT INTO table VALUES ('" + today + "','" + cflow + "','" + vat + "','" + cnn + "')");
  
              }
          }
  
          catch (SQLException exp)
          {
              System.err.println(exp);
          }
  </code></pre>
  
  <p>But with this code, when the record does not exist yet, the user input is not updated inside the database.</p>
  
  <p>Thanks for your time :)</p>