MyBatis #{param} Not Working in IntelliJ? Fix It
Problem
You try to run a MyBatis query in IntelliJ Database Console:
INSERT INTO TB_USER (USER_ID)
VALUES (#{userId})
It fails.
Why This Happens
#{} is not SQL.
It is a MyBatis parameter binding syntax.
At runtime, MyBatis converts it into:
INSERT INTO TB_USER (USER_ID)
VALUES (?)
Then JDBC binds the actual value:
? = 'A123'
IntelliJ Database Console does not know MyBatis, so it cannot interpret #{}.
Solution
Use ? (Recommended)
INSERT INTO TB_USER (USER_ID)
VALUES (?);
When executed, IntelliJ will prompt you to enter the value.
This matches exactly how MyBatis executes SQL.
Alternative: Named Parameters
VALUES (:userId)
This is IntelliJ-specific and not identical to MyBatis behavior.
Avoid: Hardcoding Values
VALUES ('A123')
This can lead to:
- Type mismatches
- Incorrect debugging assumptions
Key Takeaway
The database never sees
#{}— it only sees?.
Understanding this separation between SQL structure and parameter binding is critical for debugging.