有否无连接的ResultSet?

_i_ 2003-06-10 11:23:17
第一次在java版提问题。希望得到您的指点。
ResultSet是有连接的,但它包含我所需要的信息。在Jsp或App Client里面,我想要使用和ResultSet同样的类,但不包含连接。数据可以脱离连接而独立存在。比如像Delphi里面的TClientDataSet类。不知道Java里面是否有同样的类。或者大家是如何解决的?
谢了先。
...全文
62 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
_i_ 2003-06-10
  • 打赏
  • 举报
回复
就在这边回答吧。http://expert.csdn.net/Expert/topic/1897/1897580.xml?temp=.3481867
那边被我咔嚓了。

有无别的办法呢?
幸亏,昨天我差点想自己写一个类。不然又是一堆垃圾。
_i_ 2003-06-10
  • 打赏
  • 举报
回复
gks_cn(981530) 谢谢,我在那边给你多些,这边少些,反正满100就是。

另:Java为何这么乱啊?Delphi就一家厂商控制,所以比较纯,第三方控件也很多,不多说了。.Net好像发展势头很猛,大家有何看法?
gks_cn 2003-06-10
  • 打赏
  • 举报
回复
说实话,不回答你的问题,我还不知道,cachedrowset功能这么强大。连数据库的连接都可以一个人搞定
<%@ page import="sun.jdbc.rowset.CachedRowSet" %>
<HTML>
<HEAD>
<jsp:useBean id="Contacts" class="sun.jdbc.rowset.CachedRowSet" scope="session">
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// initialize our CachedRowSet bean
Contacts.setUsername("user");
Contacts.setPassword("password");
Contacts.setUrl("jdbc:odbc:mydsn");
// some drivers require this
Contacts.setTableName("Contacts");
Contacts.setCommand("SELECT name, telephone from Contacts");
Contacts.execute();
Contacts.first();
%>
</jsp:useBean>

<%
// get the servlet request object
javax.servlet.ServletRequest req = pageContext.getRequest();

// process updates
boolean updateRow = false;
String contactName = Contacts.getString(1);
String newValue = req.getParameter("ContactName");
if (( newValue != null) && (!newValue.equals( contactName ))) {
Contacts.updateString( 1,req.getParameter("ContactName"));
updateRow = true;
}
String contactPhone = Contacts.getString(2);
newValue = req.getParameter("ContactPhone");
if (( newValue != null) && (!newValue.equals(contactPhone))) {
Contacts.updateString( 2,req.getParameter("ContactPhone"));
updateRow = true;
}
if (updateRow) Contacts.updateRow();

// process navigation commands
if ( req.getParameter("next") != null ) {
if (! Contacts.next() ) Contacts.last();
} else if ( req.getParameter("prev") != null) {
if (! Contacts.previous()) Contacts.first();
} else if ( req.getParameter("save") != null) {
Contacts.acceptChanges();
} else if ( req.getParameter("insert") != null) {
Contacts.moveToInsertRow();
Contacts.updateString(1, "");
Contacts.updateString(2, "");
Contacts.insertRow();
Contacts.moveToCurrentRow();
Contacts.next();
} else if ( req.getParameter("delete") != null) {
Contacts.deleteRow();
if (!Contacts.next()) Contacts.last();
}
%>
<STYLE>
BODY { font-style: verdana }
</STYLE>
<TITLE>
CachedRowSetExample
</TITLE>
</HEAD>
<BODY BGCOLOR='lightgrey'>
<H2>Contacts</H2>
<FORM>
<TABLE BORDER='0'>
<TR><TD>Name:</TD><TD>Telephone number:</TD></TR>
<TR>
<TD><INPUT TYPE='text'
NAME="ContactName"
VALUE='<%=Contacts.getString(1)%>' /></TD>
<TD><INPUT TYPE="text"
NAME="ContactPhone"
VALUE='<%=Contacts.getString(2)%>' /></TD>
</TABLE>
<INPUT TYPE="submit" NAME="prev" VALUE=" < "/>
<INPUT TYPE="submit" NAME="next" VALUE=" > "/>
<INPUT TYPE="submit" NAME="insert" VALUE="Insert"/>
<INPUT TYPE="submit" NAME="delete" VALUE="Delete"/>
<INPUT TYPE="submit" NAME="save" VALUE="Save"/>
Record <%=Contacts.getRow()%> of <%=Contacts.size()%>
</FORM>
</BODY>
</HTML>


gks_cn 2003-06-10
  • 打赏
  • 举报
回复
http://oldsite.linuxaid.com.cn/developer/showdev.jsp?i=315
gks_cn 2003-06-10
  • 打赏
  • 举报
回复


清单1:简单明了的CachedRowSet初始化方法

<jsp:useBean id="Contacts"
class="sun.jdbc.rowset.CachedRowSet"
scope="session">
<%
// load database driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// initialize our CachedRowSet bean
Contacts.setUsername("dbuser"); // example userid
Contacts.setPassword("dbpassword"); // example password
Contacts.setUrl("jdbc:odbc:ContactDB"); // example DSN
Contacts.setCommand("SELECT name, telephone from Contacts");
Contacts.execute();
%>
</jsp:useBean>
WAPQQ 2003-06-10
  • 打赏
  • 举报
回复
JDO
gks_cn 2003-06-10
  • 打赏
  • 举报
回复
java.lang.Object
|
+--sun.jdbc.rowset.BaseRowSet
|
+--sun.jdbc.rowset.CachedRowSet
|
+--org.arch4j.dataaccess.visitors.ResultSetCache

All Implemented Interfaces:
Cloneable, ResultSet, ResultSetVisitor, javax.sql.RowSet, javax.sql.RowSetInternal, Serializable

--------------------------------------------------------------------------------
_i_ 2003-06-10
  • 打赏
  • 举报
回复
不好意思,贴子发了两遍,大家到http://expert.csdn.net/Expert/topic/1897/1897580.xml?temp=.3481867
去回答吧,谢谢。
有认够狠,两边都回答了,呵呵。

sun.jdbc.rowset.CachedRowset
这个包哪里找?什么文件名?
gks_cn 2003-06-10
  • 打赏
  • 举报
回复
sun.jdbc.rowset.CachedRowset
如果需要可以找我要。
提供了所有rowset所有方法,但是又是断开了数据库连接的。
那种好,我就不说了。
caoze 2003-06-10
  • 打赏
  • 举报
回复
放到Vector中或数组中都是现有的解决办法。
推荐放到Vector中。
gks_cn 2003-06-10
  • 打赏
  • 举报
回复
sun.jdbc.rowset.CachedRowset
实现了rowset的所有方法,但是有可以脱离连接存在
例子:
//输入:sql语句
//输出:查询的结果集
public CachedRowSet executeQuery(String sql) throws java.sql.SQLException {
CachedRowSet cst = new CachedRowSet();
try {
conn = db.getConnection();
ps = conn.createStatement();
rs = ps.executeQuery(sql);
cst.populate(rs);
rs.close();
}
catch (SQLException e) {
System.out.println(e.getMessage());
}
finally {
db.CleanConnection(conn, ps, rs);
}
return cst;
}
取出来了就可以直接用了
heartlessbug 2003-06-10
  • 打赏
  • 举报
回复
绝对没有
所有偶用ejb的时候,经常要自己把数据全放到一个集合里面去
是在不爽阿
ZeroC 2003-06-10
  • 打赏
  • 举报
回复
把ResultSet中的数据取出来,放到别的对象中去
因为当连接关闭的时候ResultSet会失效
firerabbit 2003-06-10
  • 打赏
  • 举报
回复
mark

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧