I got a bug today.
Background is a SPRINGMVC + MyBatis project, mapper file wrote a SQL roughly equivalent to select a from TableA where B = "123" Level
And then no matter what's in the database, it will return null.
The first response is that the SQL statement is wrong, such as the 1 and lowercase l mixed up, the parameters passed to SQL have strange spaces and so on
Then open debug log to get the PreparedStatement and corresponding parameters passed to SQL
Copy it to the console, check it out, execute it, return the result is correct, it's not a SQL problem.
Since it's not a SQL problem, you have to debug the code.
Since PreparedStatement SQL can be printed out, it does not add breakpoints from the business logic, directly to the PreparedStatement class to find the Execute method, the last breakpoint began a single step
Single-step time to find strange phenomenon, theIDE hints that the source code and class file corresponding row inconsistency, one-step debugging time code is jumping between the peers, and I am monitoring the variable reported that the variable does not exist in a class error
So the suspicion is a reference conflict.
Next, make sure that you quoted the strange class and use the following method to locate the PreparedStatement position.
Public StaticString WHERE (FinalClass CLS) { if(CLS = =NULL)Throw NewIllegalArgumentException ("null Input:cls"); URL result=NULL; FinalString Clsasresource = Cls.getname (). replace ('. ', '/'). Concat (". Class")); FinalProtectiondomain PD =Cls.getprotectiondomain (); if(PD! =NULL) { FinalCodesource cs =Pd.getcodesource (); if(cs! =NULL) result =cs.getlocation (); if(Result! =NULL) { if("File". Equals (Result.getprotocol ())) { Try { if(Result.toexternalform (). EndsWith (". Jar") | |result.toexternalform (). EndsWith (". zip") ) Result=NewURL ("Jar:". Concat (Result.toexternalform ()). Concat ("!/"). Concat (Clsasresource)); Else if(NewFile (Result.getfile ()). Isdirectory ()) Result=NewURL (result, clsasresource); } Catch(Malformedurlexception ignore) {}}} } if(Result = =NULL) { FinalClassLoader Clsloader =Cls.getclassloader (); Result= Clsloader! =NULL?Clsloader.getresource (Clsasresource): Classloader.getsystemresource (Clsasresou RCE); } returnresult.tostring (); }
When you step into idea, press Alt+f8 to check the class with the Where method, and find that the JVM does not load what I think of the msql-java-connector-5.1.63, but instead loads the java-connector in an internal class library, Positioning to look at a bit is really a problem in writing, the reason has been found.
Finally to Maven dependency, open the dependency tree, find the POM entry to load this custom connector, configure the <exclusions>, and then restart the project to resolve.
SPRINGMVC + Mybatis bug Debug SQL correct, check database but return null