把ResultSet中的数据取出来,放到别的对象中去
因为当连接关闭的时候ResultSet会失效
因为当连接关闭的时候ResultSet会失效
解决方案 »
- strutr2中的select标签,大家帮我看看
- spring 事务回滚失败
- 初学Hibernate 出了点问题,希望大家帮忙解决
- weblogic8.1支持servlet2.4吗???
- java里如何保存一个int数组到xml中
- 各位在座的,那位用j2ee1.4的,请教个问题,1.4的jsp的page指令的import属性导入.class文件出错,是不是这样啊?
- 新手请教一个问题
- 初学hibernate运行例子,报log4j错误。请大家帮忙!!!!!!!!
- Struts中如何从页面中调用FormBean??
- 谁有Master EJB的中文版?
- 关于B/S结构的应用程序的问题,高手请进!
- 利用Socket连接pop3邮件服务器,怎么区别host错误和port错误?
所有偶用ejb的时候,经常要自己把数据全放到一个集合里面去
是在不爽阿
实现了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;
}
取出来了就可以直接用了
推荐放到Vector中。
如果需要可以找我要。
提供了所有rowset所有方法,但是又是断开了数据库连接的。
那种好,我就不说了。
去回答吧,谢谢。
有认够狠,两边都回答了,呵呵。sun.jdbc.rowset.CachedRowset
这个包哪里找?什么文件名?
|
+--sun.jdbc.rowset.BaseRowSet
|
+--sun.jdbc.rowset.CachedRowSet
|
+--org.arch4j.dataaccess.visitors.ResultSetCacheAll Implemented Interfaces:
Cloneable, ResultSet, ResultSetVisitor, javax.sql.RowSet, javax.sql.RowSetInternal, Serializable --------------------------------------------------------------------------------
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>
<%@ 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>
那边被我咔嚓了。有无别的办法呢?
幸亏,昨天我差点想自己写一个类。不然又是一堆垃圾。