`

selectmethod=cursor的含义及其使用

阅读更多
连接字符串中碰到的SelectMethod=cursor
关键字: selectmethod=cursor的含义及其使用
今天在数据库连接字符串中看到了selectMethod=cursor
知道了这个用法如下:
作用:以利用服务器端的游标加快速度
使用情况:
  1.执行多个Statements的操作的时候用
  2.需要手动使用事务的时候使用



以上是在使用sqlserver数据库的连接字符串的时候使用过。

例如:jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=071008_03;SelectMethod=cursor



但是今天我将其用在oracle数据库的时候,却报出了一下的错误信息:

Io 异常: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=169869824)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))



这是个老话题,2002年在使用ejb的bmp就遇到了这个问题
连接数据库成功之后,想在一个事务中初始化多个预处理句柄时报错
dbConn.setAutoCommit(false)
for (int i = 0; i < 5; i++) {
pstmt[i] = dbConn.prepareStatement(strPreSQL[i]);
错误提示:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start manual transaction mode because there are cloned connections

怀疑MS SQL不能在一个事务中建多个预处理句柄
Resolution:
You have to add a property to the pool definition, something to do with selectMode=cursor or selectMethod=cursor. Check the driver documentation. Otherwise the driver will not allow more than one statement per connection at any given time
微软的专家告诉的
This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver."

import java.sql.*;
import java.io.*;

public class Repro{

public static void main(String args[])
{
try {
Connection con;
Statement s1 = null;
ResultSet r1 = null;
Statement s2 = null;
ResultSet r2 = null;
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Direct;User=User;Password=Password");
//fix 1
//"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Cursor;User=User;Password=Password");
con.setAutoCommit(false);

try {
s1 = con.createStatement();
r1 = s1.executeQuery("SELECT * FROM authors");

//fix 2
//r1.close();
//s1.close();

s2 = con.createStatement();
r2 = s2.executeQuery("SELECT * FROM publishers");
}
catch (SQLException ex)
{
System.out.println(ex);
}

}
catch (Exception e)
{
e.printStackTrace();
}
}
}
用SQL Server驱动一次select很多数据最好在connection string中加上SelectMethod=Cursor,以利用服务器端游标加快速度,其实不只sqlserver,oracle的jdbc,只要使用PreparedStatement,驱动默认就使用游标,sqlserver则不然,必须使用SelectMethod=Cursor才打开游标。
这点在使用jotm时,并且使用Xapool时,必须修改DataSourceFactory,把PreparedStatementPool禁掉,否则记录插的太快了,很可能是游标没来得及关闭
即使不使用jotm,大量向oracle插入数据,例如每毫秒1条,也会引发游标用完,所以大量插入数据时,应该使用oracle的批处理batchupdate.
可惜的是,微软的sqlserver的jdbc驱动不支持这个属性

分享到:
评论
1 楼 tomcat的问题 2010-11-20  
多谢多谢

相关推荐

    DBEdit2.1.1_setup.exe

    数据导入与导出工具 jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=szyes;SelectMethod=Cursor; jdbc:mysql://localhost:3306/webbase?useUnicode=true&characterEncoding=UTF-8

    省、市、地区联动选择压缩版应用实例

    户 口 所 在 地:&lt;select name="province1"&gt;&lt;/select&gt;&lt;select name="city1"&gt;&lt;/select&gt;&lt;select name="area1"&gt;&lt;/select&gt; 工 作 所 在 地:&lt;select name="province2"&gt;&lt;/select&gt;&lt;select name="city2"&gt;&lt;/select&gt;...

    struts2中常用Result类型(type)的用法和出现的问题

    struts2 常用Result类型(type)的用法 Invalid result location value/parameter错误的解决办法

    PYTHON常用库pymysql的使用,用于连接MySQL数据库

    Pymysql是一个在 Python程序语言中用来连接并操纵 MySQL数据库的第三个类库。...cursor.execute("SELECT VERSION()") # 使用 fetchone() 方法获取单条数据. data = cursor.fetchone() print("Databas

    使用HTML开发商业网站-表单控件-select课件.pptx

    使用select控件定义下拉菜单的基本语法格式如下: 表单控件 &lt;select&gt;和标签属性 标签名 常用属性 描述 &lt;select&gt; size 指定下拉菜单的可见选项数(取值为正整数)。 multiple 定义multiple="multiple"时,下拉菜单将...

    C# notepad 记事本和完整源码(仿微软)

    if (select==-1||select) { select = start; fm.richTextBox1.SelectionStart = start; MessageBox.Show("找不到" + str, "记事本"); } } else { marker=select; select = fm.richTextBox1....

    select自定义样式

    form action="" method="post"&gt; &lt;div id="divselect"&gt; 请选择特效分类 &lt;li&gt;&lt;a href="[removed];" selectid="1"&gt;导航菜单&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="[removed];" selectid="2"&gt;焦点幻灯片&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href...

    python查询sqlite数据表的方法

    本文实例讲述了python查询sqlite数据表的方法。...cursor.execute("select * from person") rows = cursor.fetchall() for row in rows: print("%s %s %s" % (row["name"], row["age"], row["address"])) conn

    省市县三级联动

    省:&lt;select id="Select1"&gt;&lt;/select&gt; 市:&lt;select id="Select2"&gt;&lt;/select&gt; 区:&lt;select id="Select3"&gt;&lt;/select&gt; &lt;script type="text/javascript"&gt; addressInit('cmb', 'cmbCity', 'cmbArea', '陕西', '宝鸡市', '...

    小型的图书管理

    method=add" method="post"&gt; 书籍名称:&lt;input type="text" name="bookname" /&gt; 书籍作者:&lt;input type="text" name="bookauthor" /&gt; 书籍价格:&lt;input type="text" name="bookprice" /&gt; ...

    OA_struts2_hibernate3_spring2.5.rar

    &lt;result name="select"&gt;/org/select.jsp &lt;action name="add_input" class="orgAction" method="add"&gt; &lt;result name="success" type="dispatcher"&gt;/org/add_input.jsp &lt;action name="add" ...

    一个年月日三下拉框联动实现JS代码

    &lt;select name=YYYY onchange="YYYYMM(this.value)"&gt; &lt;option value=""&gt;请选择 年 &lt;/select&gt; &lt;select name=MM onchange="MMDD(this.value)"&gt; &lt;option value=""&gt;选择 月 &lt;/select&gt; &lt;select name=DD&gt; &lt;option value=""&gt;...

    最新地区3级联动js调用

    &lt;select id="addressprovince"&gt;&lt;/select&gt; &lt;select id="addresscity"&gt;&lt;/select&gt; &lt;select id="addressdistrict"&gt;&lt;/select&gt; 调用:areas_init("addressprovince", "addresscity", "addressdistrict", $("#...

    省市县三级联动,包括5大洲

    &lt;select name="province"&gt;&lt;/select&gt; &lt;select name="city"&gt;&lt;/select&gt; &lt;select name="area"&gt;&lt;/select&gt; &lt;script language="javascript" defer&gt; new PCAS("province","city","area","","",""); 直接...

    表格的增删改查

    Cursor cursor = userDao_check.select(); String str = ""; if (cursor.moveToFirst()) { do { int d = cursor.getColumnIndex(MyDatabase.KEY_ID); String id = cursor.getString(d); ...

    读者写者问题课程设计

    else if(select=='2')//调用写者优先 WriterFun("peizhi.txt"); cout是否还有继续? 1. 继续 2.退出";; do { cin&gt;&gt;select; if(select!='1' && select!='2' ) cout你操作有误,请重试!"; }...

    jQuery世界城市三级联动下拉选择代码.zip

    &lt;select id="country" class="dept_select"&gt;&lt;/select&gt; &lt;select id="province" class="dept_select"&gt;&lt;/select&gt; &lt;select id="city" class="dept_select"&gt;&lt;/select&gt; jQuery世界城市三级联动下拉选择代码是一款...

    经典JS三级联动表单

    &lt;form method="post" name="test"&gt; &lt;select name="select1" onchange="select()"&gt;&lt;/select&gt; &lt;select name="select2"&gt;&lt;/select&gt; &lt;select name="select3"&gt;&lt;/select&gt; &lt;script language="javascript"&gt; &lt;!-- var ...

    基于Struts+Hibenater

    method=login" method="post"&gt; 姓名: &lt;td&gt;&lt;input type="text" name="username" /&gt; 密码: &lt;td&gt;&lt;input type="password" name="password" /&gt; 角 色: ...

    JS获取select的value和text值的简单实例

    select id = “cityList” &gt; &lt;select id = “selectId” &gt; &lt;option xss=removed&gt;第0个 &lt;/select&gt; [removed] var selectObj = document.getElementById(‘selectId’); // 通过对象添加option ...

Global site tag (gtag.js) - Google Analytics