j2ee在eclipse中为sqlexpress 2012配置hibernate配置文件

时间:2017-01-05 14:18:50

标签: java eclipse hibernate jdbc

我需要配置hibernate.cfg.xml以连接到我的sql express 2012。

我试图使用hibernate向导工具执行此操作,但它根本不连接..

在我的eclipse项目中,右键单击项目New> Hibernate配置文件(cfg.xml)。 单击下一步,然后点击"从Connection"。

获取值

新的个人资料,以及"新的连接个人资料" Windows,我选择" SQL Server"。

接下来,在Drivers下拉列表中,我点击了" New Deriver Definition"按钮和" New Deriver Definition"窗口和选定的" Microsoft SQL Server 2014 JDBC驱动程序"

在JAR列表选项卡中,我添加了" sqljdbc4.jar"我从here下载。

...在属性选项卡中,我以这种方式设置属性......

enter image description here

单击确定后,当我测试连接时,我收到以下错误:

com.microsoft.sqlserver.jdbc.SQLServerException: La connessione TCP/IP all'host localhost, porta 1433 non è riuscita. Errore: "Connection refused: connect. Verificare le proprietà di connessione. Assicurarsi che un'istanza di SQL Server sia in esecuzione sull'host e accetti le connessioni TCP/IP alla porta. Verificare inoltre che le connessioni TCP alla porta non siano bloccate da un firewall.".
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.createConnection(JDBCConnection.java:328)
at org.eclipse.datatools.connectivity.DriverConnectionBase.internalCreateConnection(DriverConnectionBase.java:105)
at org.eclipse.datatools.connectivity.DriverConnectionBase.open(DriverConnectionBase.java:54)
at org.eclipse.datatools.connectivity.drivers.jdbc.JDBCConnection.open(JDBCConnection.java:96)
at org.eclipse.datatools.enablement.msft.internal.sqlserver.connection.JDBCSQLServerConnectionFactory.createConnection(JDBCSQLServerConnectionFactory.java:27)
at org.eclipse.datatools.connectivity.internal.ConnectionFactoryProvider.createConnection(ConnectionFactoryProvider.java:83)
at org.eclipse.datatools.connectivity.internal.ConnectionProfile.createConnection(ConnectionProfile.java:359)
at org.eclipse.datatools.connectivity.ui.PingJob.createTestConnection(PingJob.java:76)
at org.eclipse.datatools.connectivity.ui.PingJob.run(PingJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

如果我从命令行ping sqlexpress是可以的(ping sqlexpress) 防火墙是不可治愈的。 从sql server网络管理

启用tcp / ip连接

1 个答案:

答案 0 :(得分:0)

当我们需要像sqlserveer express 2008/2012那样连接到sqlserver时,我们需要使用那个jar sqljdbc4.jar并为SQLServerDialect编写正确的配置,那就是所有:ex。 config(配置位置应该在名为hibernate.cfg.xml的资源文件夹中):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.micro soft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.password">login</property>
<property name="hibernate.connection.username">pass</property>
<property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.1:1433;databaseName=sensors</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQL ServerDialect</property>
</session-factory>
</hibernate-configuration>
相关问题