Hi Big Ben & Poor's, Microsoft Microsoft JDBC Driver For SQL Server has been published to the central repository maven

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
              
                    This link: https: //blog.csdn.net/nakiri_arisu/article/details/89086826
               
           
                   
                                                   
                                       
                   
                   
                                            Conclusion: Do not believe everything blog, most blog are blind copy and paste a few nonsense.
Many blog let you add the following dependencies in the maven
   <-! The MSSQLServer ->
        <dependency>
         <groupId> com.microsoft.sqlserver </ groupId>
         <artifactId> sqljdbc4 </ artifactId>
         <scope> 4.0 </ scope >
         <Version> 4.0 </ Version>
        </ dependency>
  <dependency>
   <the groupId> com.microsoft.sqlserver </ the groupId>
   <the artifactId> MSSQL-JDBC </ the artifactId>
   <Version> 6.2.0.jre8 </ Version>


12345678910111213
then let your local
mvn install: install-file -DgroupId = com.microsoft.sqlserver -DartifactId = sqljdbc4 -Dversion = 4.0 -Dpackaging = jar -Dfile = YOUR FILE DIR \ sqljdbc4.jar
own download a sqljdbc4.jar, then local introduced
huh.
The list goes on, to search it most are like this.
At that time, doubt, if that is the case following the mssql-jdbc is doing?
Later I saw a blog hi big Ben & Poor's, Microsoft Microsoft JDBC Driver For SQL Server has been published to maven central repository
and can not be combined with engineering colleagues successfully download sqljdbc4.jar, just want to understand that in fact has been introduced following the mssql-jdbc the above sqljdbc4 can be missed.
Of course, if you just look at the local introduction, then you can directly use only sqljdbc4 jar like that, the same way this time mssql-jdbc can not rely on the introduction
----------------
Copyright: this article CSDN bloggers "turned snowman 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/nakiri_arisu/article/details/89086826

 

======================================================================================================================================================

 

 We believe that through the development and application of java and SQLServer students have experienced similar problems as follows.

 The official JDBC driver provided by Microsoft is not placed in the Maven repository, so if your Java application needs to access SQL Server, you have to download to the local sqljdbc4.jar, then each time by following Maven command to install the driver:

mvn install:install-file -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar -Dfile=YOUR FILE DIR\sqljdbc4.jar


Then follows POM.xml file in your Java applications in:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc4</artifactId>
    <version>4.0</version>
</dependency>

Finally, execute:

mvn clean package

If you are using Eclipse for development, after the above steps, if the compiler does not pass, you may also need to restart Eclipse.


Perhaps the majority of developers heard the strong voice of the people, or what other reasons, Microsoft recently this month (November) will be released this driver to the Maven central repository, the next time you want to install SQL Server driver, directly in POM.xml file configuration can be carried out as follows (Microsoft offers two versions (6.1.0.jre8 and 6.1.0.jre7) drive, I am currently based development Java8, so I chose 6.1.0.jre8 this version, you can refer here ):

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.1.0.jre8</version>
</dependency>


By the current pro-test.

I hope you can happily write code.

 

reference:

http://stackoverflow.com/questions/19537396/missing-artifact-com-microsoft-sqlserversqljdbc4jar4-0

 

Attached: .NET interface to call Java Restful time to deal with a

 This problem is more difficult to use the Java language in the Date type caused, although the development process, we are using the Jada-Time framework, but the external exposure of service interfaces, or remain Date.
When Java interface time parameter type is defined as Date, we call Rest by .NET interfaces, although the look is very simple, you can call interface parameters successor, but the test results showed, the successor .NET DateTime, stored in the database through the Java service in life and death is not correct, and later to locate the problem.
For example, there is a Java CRM customer information Rest Service, .NET service calls, customer information entity Customer as follows:

Copy the code
    public class Customer
    {
        public string firstName { get; set; }

        public string lastName { get; set; }

        public DateTime createTime { get; set; }
    }
Copy the code

If we direct a New Customer, and to createTime assigned DateTime.Now:

 var ent = new Customer
 {
      firstName = "jeff",
      lastName = "wong",
      createTime = DateTime.Now,
 };

 Then inserted into the database through a Java interface is not the right time, although you can insert.

There are two solutions:
. 1, DateTime.ToUniversalTime () ToString ( "S")

This is the most simple way of stitching egress packet interface calls, as follows:

Copy the code
var sb = new StringBuffer(1024);
sb.Append("{");

sb.AppendFormat(" \"firstName\": \"{0}\",", ent.firstName);
sb.AppendFormat(" \"lastName\": \"{0}\",", ent.lastName);

sb.AppendFormat(" \"createTime\": \"{0}\"", ent.createTime.ToUniversalTime().ToString("s"));

sb.Append("}");

var postData = sb.ToString(); 
Copy the code

 

2, Newtonsoft.Json

Copy the code
 var timeConverter = new IsoDateTimeConverter
 {
         DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss",
         DateTimeStyles = DateTimeStyles.AdjustToUniversal
 };

var postData = JsonConvert.SerializeObject(ent, Newtonsoft.Json.Formatting.Indented, timeConverter);
Copy the code

Finally feeling about adding some language features Java8, such as Lambda expressions, Optional category, Stream API, the default method, method references, etc., compared to .NET, Java application development is relatively cool, of course, can not forget the Spring Boot , Spring Cloud these powerful development framework, can really write a lot less code with who knows who.

 

Guess you like

Origin www.cnblogs.com/xichji/p/11491050.html