论坛首页 Java版

『出错』请教sql server连接的两个问题,我实在找不到解决办法

浏览 2761 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2006-03-09
软件环境:
hibernate3.0.5 + spring1.2.6+Tapestry4.0+JDK5.0
配置文件:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
        <property name="url" value="jdbc:jtds:sqlserver://localhost:1433/iceroom"/>
        <property name="username" value="adong"/>
        <property name="password" value="123456"/>
    </bean>

    <!-- Hibernate SessionFactory for SQL Server -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
  <property name="mappingDirectoryLocations">
  <list>
  <value>classpath:com/iceroom/mapping/</value>
  </list>
  </property>
      <property name="hibernateProperties">
          <props>
             <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
             <prop key="hibernate.show_sql">true</prop>
             <prop key="hibernate.jdbc.fetch_size">50</prop>
             <prop key="hibernate.jdbc.batch_size">100</prop>            
          </props>
      </property>
    </bean>
    <!-- Hibernate SessionFactory for SQL Server -->
错误提示信息:
org.hibernate.exception.GenericJDBCException:
could not execute query

sql:
select article0_.id as id0_, articlecat1_.id as id1_, userbasic2_.id as id2_, article0_.reply_id as reply2_0_0_, article0_.title as title0_0_, article0_.content as content0_0_, article0_.publish_date as publish5_0_0_, article0_.reply_date as reply6_0_0_, article0_.view_number as view7_0_0_, article0_.top_flag as top8_0_0_, article0_.lock_flag as lock9_0_0_, article0_.pith_flag as pith10_0_0_, article0_.amend_number as amend11_0_0_, article0_.amend_date as amend12_0_0_, article0_.user_id as user13_0_0_, article0_.category_id as category14_0_0_, articlecat1_.category_name as category2_1_1_, articlecat1_.resume as resume1_1_, articlecat1_.head_logo as head4_1_1_, articlecat1_.visualize_loge as visualize5_1_1_, articlecat1_.flag as flag1_1_, userbasic2_.user_name as user2_12_2_, userbasic2_.head_logo as head3_12_2_, userbasic2_.visualize_loge as visualize4_12_2_, userbasic2_.qnumnber as qnumnber12_2_, userbasic2_.website as website12_2_, userbasic2_.profession as profession12_2_, userbasic2_.living_skill1 as living8_12_2_, userbasic2_.resume as resume12_2_, userbasic2_.living_skill2 as living10_12_2_ from article article0_ left outer join article_category articlecat1_ on article0_.category_id=articlecat1_.id left outer join user_basic userbasic2_ on article0_.user_id=userbasic2_.id where article0_.reply_id=0 order by article0_.publish_date desc

SQLState: HY000 
errorCode: 0 
messages: could not execute query
The amount of data read from the stream is not = length.

throwableCount: 2 
throwables: org.hibernate.exception.GenericJDBCException: could not execute query
java.sql.SQLException: The amount of data read from the stream is not = length.

  
java.sql.SQLException :
The amount of data read from the stream is not = length.
SQLState: HY000 
errorCode: 0 

你的分析:
我租用了一个服务器空间发布我的程序,本机上我使用SQL server个人版sp3,服务器上使用SQL server服务器版sp4。

本机上调试完全没有问题,如果将hibernate打印的SQL放到服务器的SQL server上运行,也完全没有问题。

但是我的程序在发布之后却报上面的错误。这个问题困扰我一个星期了,如果有解决的朋友,请告知,不胜感激:)。
   
最后更新时间:2006-03-09
我试着换用JDBC来进行数据库连接,却发现一个更奇怪的现象。

配置文件:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
        <property name="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=iceroom"/>
        <property name="username" value="adong"/>
        <property name="password" value="123456"/>
    </bean>

    <!-- Hibernate SessionFactory for SQL Server -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
  <property name="mappingDirectoryLocations">
  <list>
  <value>classpath:com/iceroom/mapping/</value>
  </list>
  </property>
      <property name="hibernateProperties">
          <props>
             <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
             <prop key="hibernate.show_sql">true</prop>
             <prop key="hibernate.jdbc.fetch_size">50</prop>
             <prop key="hibernate.jdbc.batch_size">100</prop>            
          </props>
      </property>
    </bean>
    <!-- Hibernate SessionFactory for SQL Server -->

错误信息:
org.hibernate.exception.GenericJDBCException
could not execute query
SQL: select article0_.id as id0_, userbasic1_.id as id1_, article0_.reply_id as reply2_0_0_, article0_.title as title0_0_, article0_.content as content0_0_, article0_.publish_date as publish5_0_0_, article0_.reply_date as reply6_0_0_, article0_.view_number as view7_0_0_, article0_.top_flag as top8_0_0_, article0_.lock_flag as lock9_0_0_, article0_.pith_flag as pith10_0_0_, article0_.amend_number as amend11_0_0_, article0_.amend_date as amend12_0_0_, article0_.user_id as user13_0_0_, article0_.category_id as category14_0_0_, userbasic1_.user_name as user2_12_1_, userbasic1_.head_logo as head3_12_1_, userbasic1_.visualize_loge as visualize4_12_1_, userbasic1_.qnumnber as qnumnber12_1_, userbasic1_.website as website12_1_, userbasic1_.profession as profession12_1_, userbasic1_.living_skill1 as living8_12_1_, userbasic1_.resume as resume12_1_, userbasic1_.living_skill2 as living10_12_1_ from article article0_ left outer join user_basic userbasic1_ on article0_.user_id=userbasic1_.id where article0_.reply_id=0 and article0_.category_id=14 order by article0_.top_flag desc, article0_.reply_date desc, article0_.publish_date desc 
SQLState: HY000 
errorCode: 0 
messages: could not execute query
[Microsoft][SQLServer 2000 Driver for JDBC]Underlying input stream returned zero bytes

throwableCount: 2 
throwables: org.hibernate.exception.GenericJDBCException: could not execute query
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Underlying input stream returned zero bytes

  
java.sql.SQLException
[Microsoft][SQLServer 2000 Driver for JDBC]Underlying input stream returned zero bytes
SQLState: HY000 
errorCode: 0 

你的分析:
同样,我在本机调试一点问题都没有,发布到服务器上就会报错误。同样,如果我将hibernate打印的SQL放到服务器的SQL Server中运行,完全没有问题。而且很奇怪的,请看这两个连接:http://ice.163jsp.com/Forum.external?sp=14和http://ice.163jsp.com/Forum.external?sp=13,这是两个BBS的栏目,实际上我是同样的方法和同一个HQL进行查询,只是传不同的栏目ID而已。但是一个正确,一个错误,我非常诧异。
   
0 请登录后投票
最后更新时间:2006-03-09
google过么?
参考:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4684515
http://www.mcse.ms/message389142.html
希望有所帮助!jdbc驱动换了有问题的话,换jdk试试。
   
0 请登录后投票
最后更新时间:2006-03-09
开发环境尽量与生产环境一致,这个很有好处,可以省不少麻烦。

既然现在空间是租用的,那SP4和jdk都是不能随便改的,那你就先把自己的开发环境改成SP4吧~

我用的也是jtds1.2和sp4,没有问题的,所以不是jdbc驱动问题。
   
0 请登录后投票
最后更新时间:2006-03-09
jimlaren 写道
google过么?
参考:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4684515
http://www.mcse.ms/message389142.html
希望有所帮助!jdbc驱动换了有问题的话,换jdk试试。


http://www.mcse.ms/message389142.html
这篇文章我看过,并没有具体的解决办法,有人说是jdbc驱动版本问题,我换成jdbc 2000 sp3,本机还是没有问题,服务器上依然报错。
   
0 请登录后投票
最后更新时间:2006-03-09
microsoft的jdbc好像一直都没好用的,还是试试jtds
   
0 请登录后投票
最后更新时间:2006-03-09
nihongye 写道
microsoft的jdbc好像一直都没好用的,还是试试jtds


我第一个帖子就是用jtds连接的,但是仍然报错,是什么原因呢?我用的是jtds1.0,这个版本有什么问题吗?[/i]
   
0 请登录后投票
最后更新时间:2006-03-11
引用
http://confluence.atlassian.com/display/DOC/MSSQL+Tips

google 
   
0 请登录后投票
论坛首页 Java版

跳转论坛:
JavaEye推荐