MyBatis execution statement problems generated by JDBC data-driven _java

Source: Internet
Author: User

Most of our programming processes use excellent ORM frameworks, such as MYBATIS,HIBERNATE,SPRINGJDBC, but these are not dependent on data-driven JDBC support. Although it is very convenient to use, but it is difficult to encounter some problems, such as trouble me a sleepless night, JDBC generated execution data, we look at the specific.

Typically, we use the MyBatis framework to manipulate relational databases, which are basically crud operations. The company is currently using the SQL Server database, but I have a problem with the update operation, 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:

@Test public
void Test8 () {
driverinfo driverinfo=new driverinfo ();
Driverinfo.setdrivername ("Wang Xiao");
Driverinfo.setucode ("TY888888");
Driverinfomymapper.updatedriverinfobyucode (Driverinfo);
}

Just update the driver's name according to the work number, but the SQL statements detected with SQL Server monitoring are generally as follows:

(@P0 nvarchar (4000), @P1 nvarchar (4000)) Update D_driverinfo
SET drivername = @P0, 

Of course I'm going to post my database connection string here:

Jdbc\:sqlserver\://127.0.0.1;databasename\=new;

This time the execution plan can look at:

Http://www.jb51.net/article/90264.htm

Can be seen very slowly, but by slightly modifying the connection string:

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_driverinfo
SET drivername = @P0, 
where ucode= @P1

Batch update implementation speed significantly improved, as for why change and the pros and cons please see the following official website documents

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 a small set to introduce the MyBatis through the JDBC data driven by the implementation of the statement problem, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.