为何SELECT语句WHERE子句传INT/STRING结果一致?查询结果与ResultSet相同?job_id为BIGINT(10)
Hey there! Let's break down your two questions one by one, since they're both related to MySQL behavior and JDBC ResultSet handling.
This is all down to MySQL's implicit type conversion—a behavior that kicks in when you compare values of different data types. Since your job_id column is defined as BIGINT(10), MySQL will automatically convert any string value in the WHERE clause to a numeric type before doing the comparison.
For example:
- When you run
SELECT * FROM your_table WHERE job_id = 123, you're comparing a BIGINT column to an INT value (which gets promoted to BIGINT automatically). - When you run
SELECT * FROM your_table WHERE job_id = '123', MySQL parses the string '123' into the numeric value 123 (a BIGINT), then does the same comparison as above.
Since the converted values are identical, the query results end up being the same. A quick heads-up though: if your string has non-numeric characters (like '123abc'), MySQL will still convert it to 123, which could lead to unexpected matches if you're not careful.
Absolutely reasonable—this is exactly how it's supposed to work!
The ResultSet in JDBC is specifically designed to hold the exact data returned by your database query. When you execute a SELECT statement, the database sends back all matching rows and columns, and your JDBC driver takes that data and packages it directly into the ResultSet object. So if the query results (what you'd see if you ran the query directly in a MySQL client) match what's in the ResultSet, that means the driver is working correctly and there's no data loss or corruption during the transfer.
If they didn't match, that would be a problem—like a bug in the driver, a data type conversion issue, or a configuration mistake—but consistency here is totally normal and expected.
内容的提问来源于stack exchange,提问作者yogi

