我有一个文本框。当用户在文本框中输入名称时,我希望从表格中获取详细信息
String getTxt = text.getText();
ResultSet rs=st.executeQuery("SELECT * FROM authors_4 WHERE self_authors="+getTxt);
执行此操作时出现异常
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
有什么办法可以解决这个问题吗?需要帮助
最佳答案
您缺少单引号:
st.executeQuery("SELECT * FROM authors_4 WHERE self_authors='" + getTxt + "'");
最好使用 PreparedStatement
来防止 SQL Injection攻击。
关于java - 在 mysql 的 SELECT 查询中使用 JTextBox 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15685027/