how to configure hibernate config file for sql server

前端 未结 6 1388
慢半拍i
慢半拍i 2020-11-27 13:43

Here is the config file for MySQL:


  
    o         


        
6条回答
  •  广开言路
    2020-11-27 14:38

    Properties that are database specific are:

    • hibernate.connection.driver_class: JDBC driver class
    • hibernate.connection.url: JDBC URL
    • hibernate.connection.username: database user
    • hibernate.connection.password: database password
    • hibernate.dialect: The class name of a Hibernate org.hibernate.dialect.Dialect which allows Hibernate to generate SQL optimized for a particular relational database.

    To change the database, you must:

    1. Provide an appropriate JDBC driver for the database on the class path,
    2. Change the JDBC properties (driver, url, user, password)
    3. Change the Dialect used by Hibernate to talk to the database

    There are two drivers to connect to SQL Server; the open source jTDS and the Microsoft one. The driver class and the JDBC URL depend on which one you use.

    With the jTDS driver

    The driver class name is net.sourceforge.jtds.jdbc.Driver.

    The URL format for sqlserver is:

     jdbc:jtds:sqlserver://[:][/][;=[;...]]
    

    So the Hibernate configuration would look like (note that you can skip the hibernate. prefix in the properties):

    
      
        net.sourceforge.jtds.jdbc.Driver
        jdbc:jtds:sqlserver://[:][/]
        sa
        lal
    
        org.hibernate.dialect.SQLServerDialect
    
        ...
      
    
    

    With Microsoft SQL Server JDBC 3.0:

    The driver class name is com.microsoft.sqlserver.jdbc.SQLServerDriver.

    The URL format is:

    jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
    

    So the Hibernate configuration would look like:

    
      
        com.microsoft.sqlserver.jdbc.SQLServerDriver
        jdbc:sqlserver://[serverName[\instanceName][:portNumber]];databaseName=
        sa
        lal
    
        org.hibernate.dialect.SQLServerDialect
    
        ...
      
    
    

    References

    • Hibernate Core Reference Documentation
      • 3.3. JDBC connections
      • 3.4. Optional configuration properties
    • jTDS Documentation
    • Microsoft SQL Server JDBC Driver 3.0 Documentation
    • Microsoft SQL Server JDBC Driver 2.0
    • Support Matrix for Microsoft SQL Server JDBC Driver

提交回复
热议问题