浏览 5397 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2004-10-03
<Resource name="jdbc/homeOracle" auth="Container" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/homeOracle"> <parameter><name>username</name><value>webhome</value></parameter> <parameter><name>password</name><value>webhome</value></parameter> <parameter><name>driverClassName</name> <value>oracle.jdbc.driver.OracleDriver</value></parameter> <parameter><name>url</name> <value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value></parameter> <parameter><name>maxIdle</name><value>20</value></parameter> <parameter> <name>maxActive</name> <value>0</value> </parameter> <parameter> <name>maxWait</name> <value>5000</value> </parameter> </ResourceParams> 这是HIBERNATE.CFG.XML配置的东西 <session-factory name="java:comp/env"> <property name="show_sql">true</property> <property name="connection.datasource">jdbc/homeOracle</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property> <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.username">webhome</property> <property name="hibernate.connection.password">webhome</property> <property name="hibernate.connection.pool_size">50</property> <mapping resource="bean/Jobs.hbm.xml"></mapping> <mapping resource="bean/News.hbm.xml"></mapping> <mapping resource="bean/Products.hbm.xml"></mapping> </session-factory> 我用简单的JSP查询可以查询出结果 <% DataSource ds = null; try { Context initCtx = new InitialContext(); if (initCtx == null) throw new Exception("不能获取Context!"); Context envCtx = (Context) initCtx.lookup("java:comp/env"); ds = (DataSource)envCtx.lookup("jdbc/homeOracle"); %> 但是使用HIBERNATE查询时, <% try { List jobs = new biz.JobsDB().query(); } catch(Exception e) { e.printStackTrace(); } %> 报以下错误, 严重: Could not find datasource: jdbc/homeOracle javax.naming.NameNotFoundException: Name jdbc is not bound in this Context 请问这是什么原因,为什么JSP页面能找得到的东东 HIBERNATE 找不到呢? 我配置里写的是 “jdbc/homeOracle”,而它却说 Name jdbc 找不到,是何原因呢? <property name="connection.datasource">jdbc/homeOracle</property> 我把上面这句改成下面的,这个严重错误不报了,但是还是不能运行, <property name="connection.datasource">java:comp/env/jdbc/homeOracle</property> 页面报下面错误 javax.servlet.ServletException at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536) at org.apache.jsp.jionus_jsp._jspService(jionus_jsp.java:596) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2004-10-03
看错误是servlet的错误,与hibernate无关,好好检查一下jsp代码!
另外把这三行去掉: <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.username">webhome</property> <property name="hibernate.connection.password">webhome</property> |
|
返回顶楼 | |
发表时间:2004-10-03
<%
try { List jobs = new biz.JobsDB().query(); //这个地方调Hibernate的 } catch(Exception e) { e.printStackTrace(); } %> 在上面的JSP中,我只要把第4行注释就不会出错,应该是与Hibernate有关吧, 而且用Hibernate写好的相关组件,我调试过了,是可以用的,才用Web方式来调用。 |
|
返回顶楼 | |
发表时间:2004-10-04
<session-factory name="java:comp/env"> 中的name是用来在JNDI中绑定session-factory的,我不知道你在这里写了,而且是写的"java:comp/env"是什么意思?你的datasource的JNDI名写的也有点问题,试试下面的写法。
<property name="connection.datasource">java:comp/env/jdbc/homeOracle</property> |
|
返回顶楼 | |
发表时间:2004-10-09
问题已经解决,但是出现以下问题
Hibernate: select products0_.ProductID as ProductID, products0_.ProductName as ProductN2_, products0_.ProductCategory as ProductC3_, products0_.ProductShortname as ProductS4_, products0_.Approval as Approval, products0_.InputPower as InputPower, products0_.SuctionPower as SuctionP7_, products0_.DustCapacity as DustCapa8_, products0_.PowercordLength as Powercor9_, products0_.Airpressure as Airpres10_, products0_.Seivelhose as Seivelhose, products0_.CarryingHandle as Carryin12_, products0_.ContainerLoadingqty as Contain13_, products0_.Picsmall as Picsmall, products0_.Piclarge as Piclarge, products0_.PubDate as PubDate, products0_.Bagged as Bagged from Products products0_ 00:31:23,485 WARN JDBCExceptionReporter:38 - SQL Error: 1006, SQLState: 72000 00:31:23,485 ERROR JDBCExceptionReporter:46 - ORA-01006: 赋值变量不存在 00:31:23,555 WARN JDBCExceptionReporter:38 - SQL Error: 1006, SQLState: 72000 00:31:23,555 ERROR JDBCExceptionReporter:46 - ORA-01006: 赋值变量不存在 00:31:23,565 ERROR JDBCExceptionReporter:38 - Could not execute query java.sql.SQLException: ORA-01006: 赋值变量不存在 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573) at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891) at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830) at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672) at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527) at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:205) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189) 我前面的SQL语句单独可以执行,且我也只做一个查询,不知道为什么出这个问题 |
|
返回顶楼 | |