This article describes how to use mybatis to connect to the SQLServer database. 1. Download the free version of SQLServer2014Express in www. microsoft. comen-usserver-cloudproductssql-server-editionssql-server-express.aspx for learning. Then, install and configure the default Administrator sa password. 2
This article describes how to use mybatis to connect to the SQLServer database. 1. Download SQL Server 2014 Express free edition in http://www.microsoft.com/en-us/server-cloud/products/sql-server-editions/sql-server-express.aspx for learning. Then, install and configure the default Administrator sa password. 2
This article describes how to use mybatis to connect to the SQLServer database.
1. Download SQL Server 2014 Express free edition in http://www.microsoft.com/en-us/server-cloud/products/sql-server-editions/sql-server-express.aspx for learning.
Then, install and configure the default Administrator sa password.
2. in SQL Server Configuration Manager, enable TCP/IP and restart SQLServer. Then we canUseSome database clients try to connect to the database.
3. In http://www.microsoft.com/zh-CN/download/details.aspx? Id = 11774 download the jdbc driver of SQLServer. There are simple examples and three versions of jar packages.
4. Now I have a spring + springmvc + mybatis project.UseThe database is mysql. Now I want to change to SQLServer.
First, I will introduce one of the jdbc. jar packages into the project. Here IUseIs sqljdbc4.jar.
(In debugging
Cannot load JDBC driver class 'com. microsoft. sqlserver. jdbc. SQLServerDriver'
Or Cannot create PoolableConnectionFactory (this server version is not supported. The target Server must be SQL Server 2000 or later.
And so on, it may beUseJar package version is incorrect)
Then modify jdbc. properties:
driver=com.microsoft.sqlserver.jdbc.SQLServerDriverurl=jdbc\:sqlserver\://127.0.0.1\:1433;DatabaseName=billuser=sapassword=
Modify mybatis-config.xml
Modify these two files and configure them. Then debug them with junit.
In AccountMapper. xml, write
INSERT INTO b_account ( userId, password )VALUES ( #{userId}, #{password} )
Create pojo and database tables.
Write the following debugging code in Test. java:
package net.test.modules; import javax.annotation.Resource;import net.bill.modules.dao.AccountMapper;import net.bill.modules.pojo.Account;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.BeansException;import org.springframework.context.ApplicationContext;import org.springframework.context.ApplicationContextAware;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations="/applicationContext.xml")public class BaseTest implements ApplicationContextAware{ public ApplicationContext ctxt; public void setApplicationContext(ApplicationContext arg0) throws BeansException { this.ctxt = arg0; } @Resource private AccountMapper accountMapper; @Test public void testSql(){ accountMapper.insert(new Account("16", "haha")); }}
The test is passed.