首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

用MyEclipse3.2中的hibernate怎么配数据源?作出来马上给分

2012-01-14 
求助:用MyEclipse3.2中的hibernate如何配数据源?作出来马上给分用的是TOMCAT5.5,SQLSERVER2000,在建Hibern

求助:用MyEclipse3.2中的hibernate如何配数据源?作出来马上给分
用的是TOMCAT5.5,SQLSERVER2000,在建Hibernate的时候要写connect   URL和Factory,分别写什么哦?项目等着开工啊,急!!!!

[解决办法]
建Hibernate 你指的是hibernate-cfg.xml 吗
还是什么
[解决办法]
没错~

用jndi的话,可以把datasource配置在tomcat里面


如果是driver形式需要自己写具体的参数了,如下:

<property name= "hibernate.connection.url "> jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yourdb </property>

<property name= "connection.driver_class "> com.microsoft.jdbc.sqlserver.SQLServerDriver </property

当然需要这个驱动的jar包

[解决办法]
楼主什么都是不懂,就虚心听人家说
interpb(新年快乐@曾曾胡,深怕情多累美人!!!) 说的没错,myEclipse只是plug-in.
给你个hibernate.cfg.xml的样子,你用sql server 就把相关的JAR包放进去,
再改你相关的driver-class,url,username,password和dialect
别忘了指定sample.hbm.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>

<!-- Oracle connection settings -->
<!--
<property name= "connection.driver_class "> oracle.jdbc.driver.OracleDriver </property>
<property name= "connection.url "> jdbc:oracle:thin:@192.168.0.39:1521:tarenadb </property>
<property name= "connection.username "> scott </property>
<property name= "connection.password "> tiger </property>
<property name= "dialect "> org.hibernate.dialect.OracleDialect </property>
-->

<!-- Disable the second-level cache -->
<property name= "cache.provider_class "> org.hibernate.cache.NoCacheProvider </property>

<!-- Echo all executed SQL to stdout -->
<property name= "show_sql "> true </property>
<property name= "format_sql "> true </property>

<!-- Add your mapping resource(.hbm.xml) here -->
<mapping resource= "com/tarena/netctoss/entity/Pricing.hbm.xml " />
<mapping resource= "com/tarena/netctoss/entity/User.hbm.xml " />
<mapping resource= "com/tarena/netctoss/entity/Service.hbm.xml " />
<mapping resource= "com/tarena/netctoss/entity/Admin.hbm.xml " />
<mapping resource= "com/tarena/netctoss/entity/Module.hbm.xml " />

</session-factory>

</hibernate-configuration>

[解决办法]
我看的有点摸不到头脑了
[解决办法]
楼主何不用 5.0版本的啊!图形化界面配置,全都自动生成!
[解决办法]
Yes!
[解决办法]

学习...
[解决办法]
楼主是要使用JNDI来查找数据源,这个问题我碰到过,可惜代码没在手边,我当时记得这个问题是有点复杂,除了在eclipse内配置,还要在tomcat内配置,而且我当时犯的错误就是在tomcat上,记得是tomcat的一个xml文件要修改,楼主可以看下。

[解决办法]
tomcat中配置datasource
<Context path= "/DBTest " docBase= "DBTest "
debug= "5 " reloadable= "true " crossContext= "true ">

<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to 0 for no limit.
-->

<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->

<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->

<!-- username and password: MySQL dB username and password for dB connections -->

<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->

<!-- url: The JDBC connection url for connecting to your MySQL dB.
The autoReconnect=true argument to the url makes sure that the
mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
connection. mysqld by default closes idle connections after 8 hours.
-->

<Resource name= "jdbc/TestDB " auth= "Container " type= "javax.sql.DataSource "
maxActive= "100 " maxIdle= "30 " maxWait= "10000 "
username= "javauser " password= "javadude " driverClassName= "com.mysql.jdbc.Driver "
url= "jdbc:mysql://localhost:3306/javatest?autoReconnect=true "/>

</Context>

热点排行
Bad Request.