从java填充SQL表时出错

从java填充SQL表时出错,java,jdbc,insert,Java,Jdbc,Insert,我有这个问题,我不明白为什么会出错。 错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用第1行中“from、to、subject”值(“me”、“you”、“Missed you!”)的正确语法 String from = "me"; String to = "you"; String subject = "Missed you!"; St

我有这个问题,我不明白为什么会出错。
错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解使用第1行中“from、to、subject”值(“me”、“you”、“Missed you!”)的正确语法

 String from = "me";
 String to = "you";
 String subject = "Missed you!";


 String query = "INSERT INTO emailApp (from, to, subject) VALUES ('"+from+"','"+to+"','"+subject+"')";
        st.executeUpdate(query);
TO
是SQL保留关键字。更改数据库中的两个列名,并调整查询以匹配新名称

PreparedStatement prepareStatement = 
    connection.prepareStatement("INSERT INTO emailApp (sender, recipient, subject) VALUES (?, ?, ?)");
prepareStatement.setInt(1, sender);
prepareStatement.setInt(2, recipient);
prepareStatement.setInt(3, subject);
prepareStatement.executeUpdate();

String query=“插入emailApp(发件人、收件人、主题)值(“+sender+”、“+to+”、“+subject+”)”;-仍然不工作。
TO
也是保留字是否需要向所有字段添加数据?因为它一直在说某个字段没有默认值。
from
是SQL关键字,您需要在它前面加上表名,类似于
emailApp.from
的东西可能会起作用。您还应该使用
PreparedStatement
,有关更多详细信息,请参阅…我更喜欢使用API作为hibernate等。只是尝试帮助振铃器处理错误。保险就从这个开始。
 String from = "me";
 String to = "you";
 String subject = "Missed you!";

 String query = "INSERT INTO emailApp ("columnName1", "columnName2", "columnName3") VALUES ('"+from+"','"+to+"','"+subject+"')";
    st.executeUpdate(query);