Java堂  


迟到的报道- SQLServer2005 JDBC v1.1正式版发布

Filed under: Database,JavaPlateform — Jet @ 12:49 下午
Tags: ,
原文出处: 迟到的报道- SQLServer2005 JDBC v1.1正式版发布
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

好久没有上SQL Server JDBC网站,原来早在8月29日就更新驱动了,现在是1.1的正式版。从其中一个开发者的博客上看到了更新的内容:

1. Integrated security 增强了安全连接,不过这个功能只支持 Windows 系统。我记得是需要拷贝一个dll文件

2. Client Failover, Database Mirroring support 支持 客户端失效倍援和数据库镜像功能
  数据镜像功能其实是SQL Server2005的一个新功能,现在的JDBC驱动也支持了。关于这个功能更多可参考:http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
  客户端失效倍援(不知道这个翻译是否准确)的描述是这样的:When connecting to a Sql Server 2005 Database that has a failover partner the JDBC v1.1 driver will cache failover information and retry to the failover partner on primary failure. Additionally you can use the new “failoverPartner” connection string keyword to handle initial connection failure scenarios.

3. 修复了以下上个版本里面的比较严重的bug(前面的数字是提交bug时候产生的序号,没有具体的含义)
<blockquote> <li>426389 Calling Statement.execute no longer causes an SQLException with the

message “sp_cursoropen/sp_cursorprepare: The statement parameter can

only be a single select or a single stored procedure‿ for UPDATE

WHERE queries when the selectMethod=cursor connection property is set.</li>

 <li>436718 Calling PreparedStatement.execute no longer causes an SQLException

with the message “sp_cursoropen/sp_cursorprepare: The statement

parameter can only be a batch or a stored procedure with a single

select, without FOR BROWSE, COMPUTE BY, or variable assignments‿ for

INSERT INTO queries when the selectMethod=cursor connection property is set.</li>
 <li>450639 The driver no longer throws an SQLException with the message “Server

failed to resume the transaction, desc: 4600000001.‿ when configuring

SQL Server 2005 as the JBoss JMS message store.</li>
 <li>435796 Executing SQL WRITETEXT statements no longer throws an SQLException

with the message “No TDS_RET_STATUS was found for the stored procedure

output parameters.‿</li>
 <li>424295 DatabaseMetaData.getMaxConnections no longer throws an SQLException with

the message “The configuration option ‘user connections’ does not exist,

or it may be an advanced option‿ for SQL Server 2005 servers.</li>
 <li>433394 Calling Statement.executeBatch after setting a BLOB value no longer throws

an SQLException with the message “The conversion from BLOB to BINARY is unsupported.‿</li>
 <li>435448 The driver no longer throws an SQLException with the message

“com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ‘-’‿

when sending a BigDecimal prepared statement parameter value to the server

with the 5.0 JRE.</li></blockquote>
参考资料:
JDBC 2005 v1.1 is now available.
<a href=”http://blogs.msdn.com/angelsb/archive/2006/08/22/713417.aspx” target=”_blank”>http://blogs.msdn.com/angelsb/archive/2006/08/22/713417.aspx</a>

微软官方发布SQLServer JDBC 1.1 CTP版本

Filed under: Database — Jet @ 11:38 下午
原文出处: 微软官方发布SQLServer JDBC 1.1 CTP版本
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

经过漫长的6个月的等待,微软官方终于发布了SQL Server JDBC 1.1版本的驱动,不过该版本为CTP(Community Technology Preview) 社区预览版,主要修改了所有已知的bug。
这里引用SQL Server JDBC项目一名开发人员 Angel 的一段说明:

Announcing the June 2006 Community Tech Preview of the JDBC 2005 driver:
http://www.microsoft.com/downloads/details.aspx?familyid=f914793a-6fb…

This preview contains all the changes of CTP 1 including Integrated
Security, it includes rollup fixes for all the QFEs we have shipped to date
and we have addressed most customer issues filed through the product
feedback center.

To round it off we have also added a brand new feature: Client Failover. As
far as I know this is the first JDBC driver to take advantage of Sql Server
2005 Database Mirroring. This feature has been fully documented for this
CTP, we could really use feedback on both the functionality and the docs.

For a complete change list take a look at the release.txt file that ships
with the package, for the first time we are providing comprehensive
information on the work we have done since v1.0, let us know if this is
helpful information.

下载地址:http://msdn.microsoft.com/data/ref/jdbc/

拿到了SQL Server JDBC V1.1 CTP驱动

Filed under: Database,JavaPlateform — Jet @ 11:29 下午
原文出处: 拿到了SQL Server JDBC V1.1 CTP驱动
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

目前微软官方提供的SQL Server JDBC的最后版本为1.0,但是该版本的驱动有许多bug,今天得到的这个1.1版本的驱动是微软JDBC小组内部发行的一个版本,解决了许多已知的bug,比如:

Bug Details: Statement.execute() returns incorrect results for stored procedures

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=dc43eb80-69b5-4137-8671-9f4e813ce259

Bug Details: JDBC 2005 GA Driver error when running a callablestatement on SQLServer 2000

http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=3fcf439d-79ed-44d9-bbbf-320e4ee25d89

Exception Message: “SQL Error: A server cursor is not allowed on a remote stored procedure or stored procedure with more than one SELECT statement. Use a default result set or client cursor”

Bug Details: JDBC Driver executeBatch does not work with INSERT statement

http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=e13a8009-7466-4803-ba19-6bfd4b5f8966

Exception Message: “java.sql.BatchUpdateException: com.microsoft.sqlserver.jdbc.SQLServerException: sp_cursoropen/sp_cursorprepare: The statement parameter can only be a single select or a single stored procedure.“

Bug Details: SQL2005 JDBC Driver bug with time zone handling **Available as a QFE**

http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=e73c8b79-53a6-4779-98f1-71c0043179eb

如果需要的可以在下面留言。
现在微软官方已经推出了新的正式版的1.1版本的驱动,大家可以在官方下载:http://msdn.microsoft.com/data/ref/jdbc/

SQL Server JDBC 1.0 中关于executeBatch()方法的两个bug

Filed under: Database — Jet @ 4:08 下午
原文出处: SQL Server JDBC 1.0 中关于executeBatch()方法的两个bug
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

SQL Server JDBC的bug真是多多啊, 今天又发现两个很奇怪的错误, 查了网上的一些资料, 果然是驱动的bug. 情况是这样的:
将SQL Server JDBC的连接字段中SelectMethod设置为cursor, 然后执行下面一段代码:

  1. PreparedStatement stmt = connection.prepareStatement("insert into table1
  2. values (?, ?)");
  3. stmt.setInt(1, 1);
  4. stmt.setInt(2, 2);
  5. stmt.addBatch();
  6. stmt.executeBatch();
  7. stmt.close();

这个时候会产生 “sp_cursoropen/sp_cursorprepare: 语句参数只能是单个 SELECT 语句或单个存储过程。” 的SQLServerException, 同时数据不能写入到数据库中.
第二个错误是使用CallableStatement调用SQL Server的存储过程的时候, 如果使用executeBatch()方法的时候, 数据不能进行写入或更新, 并且没有抛出任何的异常.
查了一下微软的bug中心, 发现以上两个错误果然是JDBC的bug.
Bug Details: JDBC Driver executeBatch does not work with INSERT statement
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackid=e13a8009-7466-4803-ba19-6bfd4b5f8966
Bug Details: Statement.execute() returns incorrect results for stored procedures
http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=dc43eb80-69b5-4137-8671-9f4e813ce259

bug记录上面显示状态为fixed, 但是对外公开的最新的驱动还没有更新, 只能是耐心的等待了 :(

参考资料:
Batch inserts dont work with PreparedStatement and selectMethod=cursor
http://groups.google.com/group/microsoft.public.sqlserver.jdbcdriver/browse_thread/thread/97b17f5b551ad146/385a82eb5315dccc?q=Batch+inserts+dont+work+&rnum=1

一篇专门介绍SQL Server JDBC的教程《MS_SQLSERVER.JDBC 》

Filed under: Database,JavaPlateform — Jet @ 3:48 下午
原文出处: 一篇专门介绍SQL Server JDBC的教程《MS_SQLSERVER.JDBC 》
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

市面上关于JDBC的介绍大多是关于Oracle或MySQL的, 而关于SQL Server JDBC的资料不是很多. 昨天从网上找到一篇专门介绍SQL Server JDBC的文章, 虽然是内容是关于JDBC2000的, 但是现在最新的SQL Server JDBC1.0对旧版本的改变大多是修改许多bug, 外部的API用法或者名称改变的不多, 所以这篇教程依然是一个非常好的参考资料.

教程原地址: http://www.csuchico.edu/computing/JAVAINFO/MS_SQLSERVER.JDBC/Preface.html

为方便大家, 我将其做成了chm格式的文档. 可以在本地下载.

SQL Server JDBC 1.0中提高Select的效率

Filed under: Database — Jet @ 3:00 下午
原文出处: SQL Server JDBC 1.0中提高Select的效率
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

如下一段代码, 其中myArray为一个存储数据的数组:

  1. // 建立Connection
  2. for(int i = 0; i < myArray.length; i ++){ 
  3.     link = myArray[i];
  4.     if(link == null) 
  5.         continue;
  6.     else 
  7.         link = link.replaceAll("'", "''");
  8.     String query = "Select Top 1 a_id From _osd_article Where link='" + link + "'";
  9.     Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  10.     ResultSet rs = s.executeQuery(query);
  11.     boolean have = rs.next();
  12.     rs.close();
  13.     s.close();
  14.     if(have) 
  15.         continue;
  16. } 
  17. // 释放Connection...

执行之后发现Select的速度非常的慢, 并且在执行的过程中出现CPU使用率100%的情况. 查阅了一些资料, 原来是由于SQL Server JDBC 1.0默认的SelectMethod为direct造成的. 在direct模式下, 每一个Connection必须只对应一个Statement, 所以在查询的时候系统资源占用非常的高; 另外, direct模式下也容易产生互锁的事务. 如果修改为cursor模式就可以了. 关于驱动连接的参数以及详细的说明可以见参考资料.

参考资料:
Why is com.microsoft.jdbc.sqlserver.S-QLServerDriver so slow?
http://groups.google.com/group/microsoft.public.sqlserver.jdbcdriver/browse_thread/
thread/c11b52262f313bcb/c293b3aef59bb71a?q=select+slow&rnum=2

(SQL Server JDBC) Connection String Properties
http://www.csuchico.edu/computing/JAVAINFO/MS_SQLSERVER.JDBC/jdbcsqlsrv3.html
JDBC连SQL SERVER数据库常见问题
http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=123&threadID=18621

JDBC优化技巧 – Performance Tips for the Data Tier (JDBC)

Filed under: Database,JavaPlateform — Jet @ 6:41 上午
Tags:
原文出处: JDBC优化技巧 – Performance Tips for the Data Tier (JDBC)
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

今天发现一篇非常棒的关于JDBC优化的文章, 题目名为《Performance Tips for the Data Tier (JDBC)》,中文翻译成《JDBC优化技巧》。
英文版地址:http://www.theserverside.com/articles/article.tss?l=JDBCPerformance
我发现一位名为陈先波的网友已经将其翻译成了中文,大家也可以参考下:http://blog.csdn.net/turbochen/archive/2004/06/13/8107.aspx

最后,我将这两个版本合而为一, 做了一个chm格式的文件,方便大家的查询使用。文件下载

密码保护:JDBC操作SQL Server小结

Filed under: Database,JavaPlateform — Jet @ 4:06 上午
原文出处: 密码保护:JDBC操作SQL Server小结
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

这是一篇受密码保护的文章。您需要提供访问密码: