import java.sql.*;import sun.jdbc.rowset.*;public class DbBean {
private Connection conn = null;
private Statement ps = null;
private ResultSet rs = null;
private OpenDbBean db = new OpenDbBean();
//返回查询的记录集
public CachedRowSet getCachedRowSet(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;
} //执行查询语句,不带回记录集
public String ExcuteSql(String sql) {
try {
conn = db.getConnection();
ps = conn.createStatement();
ps.execute(sql);
ps.close();
}
catch (SQLException e) {
return e.getMessage();
}
finally {
try {
db.CleanConnection(conn, ps, rs);
}
catch (SQLException e) {
return e.getMessage();
} }
System.out.println("恭喜数据库执行成功");
return "恭喜数据库执行成功";
}
}
在jsp中:
oa.DbBean db=new oa.DbBean();
sun.jdbc.rowset.CachedRowSet rs= db.getCachedRowSet("select * from ApproveView where ApinAgreFlag='0' and EminNumber="+EminNumber);
while (rs.next()) {
%>
<tr bgcolor="EEEEEE" onMouseOver="this.style.backgroundColor='#fafafa';" onMouseOut=this.style.backgroundColor='#ebebeb'>
<td align="right"><div align="center"><%=oa.Tools.toGBKString(rs.getString("toAplyyEmin"))%></div></td>
<td align="right"><div align="center"><%=oa.Tools.toGBKString(rs.getString("AccoName"))%></div></td>
<td align="right"><div align="center">
<input type="button" name="Submit2" value="审批" onclick="window.location='approve_audit.jsp?ApinNumber=<%=rs.getString("ApinNumber")%>'">
<input type="button" name="Submit" value="返回" onClick="window.location='AnnounceIndex.jsp'">
</div></td>
</tr>
<%
}
private Connection conn = null;
private Statement ps = null;
private ResultSet rs = null;
private OpenDbBean db = new OpenDbBean();
//返回查询的记录集
public CachedRowSet getCachedRowSet(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;
} //执行查询语句,不带回记录集
public String ExcuteSql(String sql) {
try {
conn = db.getConnection();
ps = conn.createStatement();
ps.execute(sql);
ps.close();
}
catch (SQLException e) {
return e.getMessage();
}
finally {
try {
db.CleanConnection(conn, ps, rs);
}
catch (SQLException e) {
return e.getMessage();
} }
System.out.println("恭喜数据库执行成功");
return "恭喜数据库执行成功";
}
}
在jsp中:
oa.DbBean db=new oa.DbBean();
sun.jdbc.rowset.CachedRowSet rs= db.getCachedRowSet("select * from ApproveView where ApinAgreFlag='0' and EminNumber="+EminNumber);
while (rs.next()) {
%>
<tr bgcolor="EEEEEE" onMouseOver="this.style.backgroundColor='#fafafa';" onMouseOut=this.style.backgroundColor='#ebebeb'>
<td align="right"><div align="center"><%=oa.Tools.toGBKString(rs.getString("toAplyyEmin"))%></div></td>
<td align="right"><div align="center"><%=oa.Tools.toGBKString(rs.getString("AccoName"))%></div></td>
<td align="right"><div align="center">
<input type="button" name="Submit2" value="审批" onclick="window.location='approve_audit.jsp?ApinNumber=<%=rs.getString("ApinNumber")%>'">
<input type="button" name="Submit" value="返回" onClick="window.location='AnnounceIndex.jsp'">
</div></td>
</tr>
<%
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货