1、连接
SqlServer属于比较老的版本,驱动使用sqljdbc4-3.0.jar可以成功连接。
jdbc-url: jdbc:sqlserver://localhost:1433;DatabaseName=test
username: sa
password: 123456
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
2、引入本地jar
本地jar有条件最好上传到maven私服。
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/sqljdbc4-3.0.jar</systemPath>
</dependency>
此种方式引入的jar包放在项目文件下:E:\IdeaWorkspace\NewProject。
此种方式可以打包带上此jar包。
3、2000的批量插入
2000的版本不支持insert into table(x,x) values(a,a),(b,b)这种批量插入。注意这个“,”逗号。
请使用
insert into table(x,x)
values
<foreach collection="list" separator="UNION all" item="item">
select #{item.a,jdbcType=VARCHAR}, #{item.a,jdbcType=DECIMAL}
</foreach>
即
insert into table(x,x) values
select a,a union all
select b,b union all
select c,c
此种方式入值
4、Mybatis的字符比较
<if test="#{item.xxsId} != 'a'.toString()"></if>
或者
<if test='#{item.xxsId} != "a"'></if>