Most of our programming process use excellent ORM frameworks, such as MyBatis, Hibernate, SpringJDBC, but these are inseparable from the support of data-driven JDBC. Although it is very convenient to use, it is really difficult to encounter some problems, such as the problem that has troubled me not sleeping well all night. JDBC generates execution data. Let's take a look at the details.
Usually we use the MyBatis framework to operate relational databases, and the basic one is crud operations. Currently, the company is using the SqlServer database, but I have a problem when I am performing the update operation. The specific situation is as follows:
Mapper.xml content:
<update id="updateDriverInfoByUcode" parameterType="com.sypro.earth.model.DriverInfo" >update D_DriverInfo<set ><if test="driverName != null" >DriverName = #{driverName,jdbcType=NVARCHAR},</if></set><where>Ucode=#{ucode,javaType=string,jdbcType=VARCHAR,typeHandler=com.sypro.earth.typehandler.ExampleTypeHandler}</where></update> The Test code is as follows:
@Testpublic void Test8(){DriverInfo driverInfo=new DriverInfo();driverInfo.setDriverName("Wang Xiaoer");driverInfo.setUcode("TY888888");driverInfoMyMapper.updateDriverInfoByUcode(driverInfo);} I just update the driver's name according to the work number, but the SQL statements detected using SQL Server to monitor are roughly as follows:
(@P0 nvarchar(4000),@P1 nvarchar(4000))update D_DriverInfoSET DriverName = @P0, WHERE Ucode=@P1
Of course, I want to post my database connection string here:
jdbc/:sqlserver/://127.0.0.1;databaseName/=new;
You can check the execution plan at this time:
//www.VeVB.COM/article/90264.htm
It can be seen that it is very slow, but by modifying the connection string a little:
jdbc/:sqlserver/://127.0.0.1;databaseName/=new;sendStringParametersAsUnicode=false
Then execute the test code and you can see
(@P0 varchar(8000),@P1 varchar(8000))update D_DriverInfoSET DriverName = @P0, WHERE Ucode=@P1
The execution speed of batch updates has been significantly improved. As for why the changes and the pros and cons of changes, please refer to the official website document below.
https://technet.microsoft.com/zh-cn/library/ms378857%28SQL.90%29.aspx
https://technet.microsoft.com/zh-cn/library/ms378988%28v=sql.90%29.aspx
http://d.hatena.ne.jp/gnarl/20110706/1309945379
The above is the execution statement problem generated by MyBatis through JDBC data driver introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!