Hibernate里配置为什么不能连接到sql server数据库
发布网友
发布时间:2022-04-14 09:52
我来回答
共4个回答
热心网友
时间:2022-04-14 11:22
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">
jdbc:sqlserver://localhost:1433;databaseName=Info
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">Info</property>
<property name="connection.password">sa2005</property>
<property name="connection.driver_class">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/info/entity/StuScore.hbm.xml" />
</session-factory>
</hibernate-configuration>
这段配置我是用MyEclipse生成的,测试成功,但是我一般不用这个配置都是在applicationContext.xml配置文件里面配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"></property>
<property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=Info"></property>
<property name="username" value="sa"></property>
<property name="password" value="sa2005"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="DataSource"></property>
<property name="mappingResources">
<list>
<value>com/info/entity/StuScore.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>
<bean id="StuScoreDao" class="com.info..impl.StuScoreDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="StuScoreBiz" class="com.info.biz.impl.StuScoreBizImpl">
<property name="stuScoreDao" ref="StuScoreDao"></property>
</bean>
<bean name="/toAdd" class="com.info.web.action.StuScoreAction">
<property name="stuScoreBiz" ref="StuScoreBiz"></property>
</bean>
<bean name="/toSelect" class="com.info.web.action.StuScoreAction">
<property name="stuScoreBiz" ref="StuScoreBiz"></property>
</bean>
</beans>
热心网友
时间:2022-04-14 12:40
hibernate有连不到的数据库?
## MS SQL Server
#hibernate.dialect org.hibernate.dialect.SQLServerDialect
#hibernate.connection.username sa
#hibernate.connection.password sa
这段代码是从hibernate.properties中拷贝的,各种数据库的连接都有。你自己找出来看看。一看就知道了。
目录:hibernate-distribution-3.3.2.GA\project\etc
热心网友
时间:2022-04-14 14:14
你看看 是不是密码和用户名那里错误了没,还是没有驱动包
热心网友
时间:2022-04-14 16:06
查看hibernate API 有例子按例子来