java - SQL语句语法错误时ResultSet的值?

标签 java mysql jdbc

我正在使用 mySQL。正如您所看到的,SELECT 处的 SQL 语句是错误的。那么,我想知道 rs 的值是多少? 我希望得到一些建议。非常感谢您;

String sql = "SELCT * FROM user WHERE username = '" + username + "' and password = '" + password + "'";
ResultSet rs = stm.executeQuery(sql); 

最佳答案

没有任何值(value),因为 Statement.executeQuery(String)会抛出 SQLException 。正如链接的 Javadoc 所说,

Returns: a ResultSet object that contains the data produced by the given query; never null

Throws: SQLException - if a database access error occurs, this method is called on a closed Statement, the given SQL statement produces anything other than a single ResultSet object, the method is called on a PreparedStatement or CallableStatement

关于java - SQL语句语法错误时ResultSet的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53983845/

相关文章:

java - RandomAccessFile 将 ETX M 添加到文件开头

java - 检查 '0000-00-00' 的时间戳,无需转换

php - 使用 UNION 查询在 while 语句中获取总数

mysql - 如何将日期字符串 "yyyy-mm-ddThh:mm:ssZ"转换为时间戳

java - 如何让 postgres JDBC 在 Scala Mac OS 中工作?

java - 使用 Liferay 6.1 在 Tomcat 7 环境中设置 JNDI

java - maven 编译错误 - 无法执行目标 org.apache.maven.plugins :maven-compiler-plugin:3. 5.1:compile

java - 如何在jsp页面中使用if条件比较两个字符串?

mysql - 为什么mysql make delete offset?

mysql - 即使生成 csv,实体管理器也会抛出 "ResultSet is from update. No data"