0

I'm trying to delete an entry from a SQLite database with java, the code I'm using is this:

      public static void main( String args[] )
  {
    Connection c = null;
    Statement stmt = null;
    try {
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:students.db");
      c.setAutoCommit(false);

      stmt = c.createStatement();
      String sql = "DELETE FROM Grade12 WHERE Name = james";
      stmt.executeUpdate(sql);
      c.commit();
      stmt.close();
      c.close();
    } catch ( Exception e ) {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }
  }

But I keep getting the error java.sql.SQLException: no such column: james

Anyone know how to fix this?

2
  • where name = 'james' Commented Sep 8, 2014 at 11:24
  • You might want to try your SQL statement in your database first. Some databases also help you creating those queries. Then you use the statement which worked, and you are fine. Commented Sep 8, 2014 at 11:25

3 Answers 3

3

Try with qoutes:

String sql = "DELETE FROM Grade12 WHERE Name = 'james'";
Sign up to request clarification or add additional context in comments.

Comments

3

Please enclose james in quotes and try it out.

String sql = "DELETE FROM Grade12 WHERE Name = 'james'";

Comments

2

Try

String sql = "DELETE FROM Grade12 WHERE Name = 'james'"

instead of

String sql = "DELETE FROM Grade12 WHERE Name = james"

1 Comment

@theThird Please try your query on database first to make sure that the query you are using is right. Sometime it's gets frustrating for no reason. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.