Java Connection SQL Server (version 8)

Source: Internet
Author: User

For the old SQL Server 2000, the connection method is a bit special.


1, download the SQL JDBC driver, 3.0 version of the jar package (must be 3.0 version, 4.0 version can only be used in SQL Server 2005 version above, and Maven repository can not find, only to join the local warehouse or directly into the project)

http://download.csdn.net/detail/clementad/8862363


2., import the jar package to the local warehouse or the project directory

If you put it in the project directory, add it in the Pom.xml file:

<dependency><groupId>com.microsoft</groupId><artifactId>sql-server</artifactId> <version>1.0.0</version><scope>system</scope><systempath>${project.basedir}/src/ Main/webapp/web-inf/lib/sqljdbc4.jar</systempath></dependency>

3. Configure the Db.properties file:

Sql.server.driverclass=com.microsoft.sqlserver.jdbc.sqlserverdriversql.server.url=jdbc:sqlserver://

4, configure the data source (take Hikari data source as an example) and sessionfactory, etc.:

<!--SQL Server Hikari Datasource--><bean id= "Sqlserverdatasourcehikari" class= " Com.zaxxer.hikari.HikariDataSource "><property name=" Driverclassname "value=" ${db.driverclass} "/>< Property Name= "Jdbcurl" value= "${sql.server.url}"/><property name= "username" value= "${sql.server.username}"/ ><property name= "Password" value= "${sql.server.password}"/><!--configured to True when a read-only database is connected, security-->< Property Name= "ReadOnly" value= "false"/><!--the maximum length of time (in milliseconds) to wait for a connection pool to allocate a connection, a connection that exceeds the length of time that is not available will occur SqlException, default: 30 Seconds-- <property name= "ConnectionTimeout" value= "30000"/><!--the maximum length of time (in milliseconds) for a connected idle state, and the timeout is released (retired), default: 10 minutes-- <property name= "IdleTimeout" value= "600000"/><!--the lifetime of a connection (milliseconds), timed out and not being used is released (retired), default: 30 minutes, Recommended setting is less than 30 seconds longer than database timeout--><property name= "maxlifetime" value= "1800000"/></bean><bean id= " Sqlserversessionfactory "class=" Org.mybatis.spring.SqlSessionFactoryBean "><property name=" DataSource "ref=" Sqlserverdatasourcehikari "/><property name= "mapperlocations" value= "Classpath:com/xjj/mapper/*.xml"/></bean><bean class= " Org.mybatis.spring.mapper.MapperScannerConfigurer "><property name=" Basepackage "value=" Com.xjj.dao "/> <property name= "Annotationclass" value= "com.xjj.annotation.SqlServerDb"/><!--scan only DAO that is labeled by @sqlserverdb-- ><property name= "Sqlsessionfactorybeanname" value= "Sqlserversessionfactory"/></bean>

This makes it possible to connect successfully.

Other detailed code (DAO, JUnit, etc.) please refer to: Https://github.com/xujijun/MyJavaStudio




Copyright NOTICE: This article is the original article, reprint please indicate the CSDN blog which is transferred from Clement-xu.

Java Connection SQL Server (version 8)

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.