Exception in thread “main” java.sql.SQLException: near “s”: syntax error

前端 未结 2 1655
逝去的感伤
逝去的感伤 2021-01-23 06:45

I wrote a program that populates a database with a list of words. Problem is, it throws up the \"Exception in thread \"main\" java.sql.SQLException: near \"s\": syntax error\" e

2条回答
  •  盖世英雄少女心
    2021-01-23 07:17

    Use PreparedStatement to avoid problems with erroneous input:

    PreparedStatement p = c.prepare("INSERT INTO WORDS (ID,CAT,WORD) VALUES(?, ?, ?)");
    p.setInt(1, i);
    p.setString(2, wordcat);
    p.setString(3, word);
    p.execute();
    //commit results if using InnoDB, etc
    

提交回复
热议问题