'connection url for sql server

I downloaded microsfot's jdbc driver, and I am not sure what the connection.url should be?

 <property name="connection.driver_class">org.microsoft.sqlserver.jdbc</property>
 <property name="connection.url">jdbc:</property>

  ..
  <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

i configured sqlexpress to work via tcpip and a static port already.



Solution 1:[1]

Connection strings are database dependent. You should take a look at a good reference web site.

If you're trying to connect to SQL Server from a Java application, try this:

jdbc:microsoft:sqlserver://<HOST>:<PORT>[;DatabaseName=<DB>]
com.microsoft.jdbc.sqlserver.SQLServerDriver

Solution 2:[2]

Complete hibernate cfg property (MS SQL server) is as follows:

com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc:sqlserver://localhost:1433;databaseName=jbpm_shared_services dbo

<property name="hibernate.connection.username">demoid</property>
<property name="hibernate.connection.password">March2017</property>

<property name="hibernate.hbm2ddl.auto">create</property>

<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>

<property name="show_sql">true</property>

<mapping class="com.knook.model.DocumentConfig"/>
<mapping class="com.knook.model.DocumentDetail"/>

If the database is someother, then you can change the hibernate.dialect, hibernate.connection.url and hibernate.connection.driver_class

values for hibernate.hbm2ddl.auto can be auto, create, update, none

Solution 3:[3]

This configuration worked for me: hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- JDBC Database connection settings -->
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=YOUR_DATA_BASENAME</property>
        <property name="connection.username">YOUR_USER_NAME</property>
        <property name="connection.password">YOUR_PASSWORD</property>

        <!-- JDBC connection pool settings ... using built-in test pool -->
        <property name="connection.pool_size">1</property>

        <!-- Select our SQL dialect -->
        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

        <!-- Echo the SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Set the current session context -->
        <property name="current_session_context_class">thread</property>

    </session-factory>

</hibernate-configuration>

Maven pom.xml

<!-- Hibernate 5.6.3-->
        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.6.3.Final</version>
        </dependency>
        <!-- Hibernate Validator -->
        <!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.2.0.Final</version>
        </dependency>

        <!-- SQL SERVER -->
        <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>9.4.1.jre8</version>
        </dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ed Altorfer
Solution 2 TechSingh
Solution 3 sam7kand