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>
<pr开发者_开发知识库operty 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.
Here you go:
<property name = "hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name = "hibernate.connection.driver_class" value = "com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name = "hibernate.connection.url" value = "jdbc:sqlserver://localhost;databaseName=cust;instanceName=SQLEXPRESS;"/>
<property name = "hibernate.connection.username" value = "sa"/>
<property name = "hibernate.connection.password" value = ""/>
<property name = "hibernate.show_sql" value="true"/>
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
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
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>
精彩评论