当你打开一个statement的时候,可以选择不同的类型,可以达到你的目的!
createStatement
public Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws SQLExceptionCreates a Statement
Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
a new Statement object that will generate ResultSet objects with the given type and concurrency
Throws:
SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
Since:
1.2
createStatement
public Statement createStatement(int resultSetType,
int resultSetConcurrency)
throws SQLExceptionCreates a Statement
Parameters:
resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
Returns:
a new Statement object that will generate ResultSet objects with the given type and concurrency
Throws:
SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
Since:
1.2
//创建statement实例
请问这是什么原因...
请问怎样才能指出TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY的包呢?我用的是jsp...我是这样写的...
<%@page import="java.sql.*"%>
还不行么?...
to yhc0125(小程):
TYPE_SCROLL_SENSITIVE我也试过了...
也抱错:"未定义变量:TYPE_SCROLL_SENSITIVE"
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
java.sql.ResultSet.CONCUR_UPDATABLE
如果还不行,那就是你设置的classpath有问题。
stmt=conn.createStatementTYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
为
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);TYPE_SCROLL_SENSITIVE比TYPE_SCROLL_INSENSITIVE少了synchronize,如果你需要同步修改/查询数据库的话,可以使用TYPE_SCROLL_SENSITIVE;否则为了效率可使用TYPE_SCROLL_INSENSITIVE。