还是数据库session的问题

wdllove 2002-11-05 10:25:43
我做了两个类,一个连接数据库,一个是分页的(网上下的)
分页的类引用连接数据库的类public class page extends DBConnection

现在的问题是我用完连接数据库的类能关闭,<jsp use id=sqlbean> 网页里用<%sqlbean.close()%>

但不知道怎么关闭分页的类<jsp use id=page>网页里用<%page.close();%>出错
好像是不能关闭sqlbean的东西.

用分页打开的网页数据库里的session都没关,所以出错,
怎么能关闭分页这个类....

谢谢

...全文
113 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdllove 2002-11-06
  • 打赏
  • 举报
回复

package oraclebbs;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class DBConnection
{

public DBConnection()
{
db_type="oracle";
user="etjg";
password="etjg";
db_ip="192.168.0.2";
db_port="1521";
db_uid="oracle81";
//String db_driver="";
db_url="jdbc:odbc:etjg";

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException classnotfoundexception)
{
System.out.println("**********Could not load the driver11111.************");
classnotfoundexception.printStackTrace();
}
String s1 = user + "/" + password + "@" + db_ip + ":" + db_port + ":" + db_uid;
try
{
db_conn = DriverManager.getConnection("jdbc:oracle:thin:"+s1);
db_stmt=db_conn.createStatement();
}
catch(SQLException sqlexception)
{
//out.println("Creat connection error.");
System.out.println("**********Could not load the driver2222.************");
sqlexception.printStackTrace();
}

}

public void setuser(String s)
{
user = s;
}

public void setpassword(String s)
{
password = s;
}

public String getuser()
{
return user;
}

public String getpassword()
{
return password;
}

public String getdbtype()
{
return db_type;
}

public int getrecordcount()
{
return record_count;
}

public int getfieldcount()
{
return field_count;
}

public ResultSet executeQuery(String s)
throws SQLException
{
db_stmt = db_conn.createStatement();
int i = s.indexOf("from");
if(i < 0)
i = s.indexOf("FROM");
String s1 = s.substring(i);
s1 = "select count(*) " + s1;
db_rset = db_stmt.executeQuery(s1);
if(db_rset.next())
record_count = db_rset.getInt(1);
db_rset = db_stmt.executeQuery(s);
ResultSetMetaData resultsetmetadata = db_rset.getMetaData();
field_count = resultsetmetadata.getColumnCount();
return db_rset;
}

public int executeUpdate(String s)
throws SQLException
{
db_stmt = db_conn.createStatement();
return db_stmt.executeUpdate(s);
}

public String getColumnName(int i)
throws SQLException
{
ResultSetMetaData resultsetmetadata = db_rset.getMetaData();
return resultsetmetadata.getColumnName(i);
}

public String getData(int i)
throws SQLException
{
return db_rset.getString(i).trim();
}

public String getData(String s)
throws SQLException
{
return db_rset.getString(s).trim();
}

public boolean next()
throws SQLException
{
return db_rset.next();
}

public void close()
throws SQLException
{
if(db_conn != null)
db_conn.close();
if(db_stmt != null)
db_stmt.close();
if(db_rset != null)
db_rset.close();
}

public Connection getConnection()
{
return db_conn;
}

public CallableStatement spCall(String s)
throws Exception
{
return db_conn.prepareCall(s);
}

public String db_ip;
public String db_port;
public String db_uid;
public String user;
public String password;
public String db_driver;
public String db_url;
public String db_type;
public String Sqlstring;
public Connection db_conn;
public Statement db_stmt;
public ResultSet db_rset;
public int record_count;
public int field_count;
}
wdllove 2002-11-06
  • 打赏
  • 举报
回复
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-6-14 16:28:28
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: page.java

package oraclebbs;

import java.sql.*;
import oraclebbs.*;

// Referenced classes of package com.shlt.dbconnection:
// DBConnection

public class page extends DBConnection
{

public page()
{
sql = "";
sql2 = "";
tablename = "";
getPam = "";
innerjoin = "";
where = "";
orderby = "";
id = "";
page_count = 0;
page = 1;
page_size = 20;
page_desc = "";
}

public ResultSet display()
throws SQLException
{
boolean flag = setSql();
if(!flag && sql == "")
return null;
try
{
super.db_stmt = super.db_conn.createStatement(1004,1007);
int i = sql.indexOf("from");
if(i < 0)
i = sql.indexOf("FROM");
String s = sql.substring(i);
s = "select count(*) " + s;
super.db_rset = super.db_stmt.executeQuery(s);
if(super.db_rset.next())
super.record_count = super.db_rset.getInt(1);
if(super.record_count != 0)
{
if(sql2.equals("") || page_size == 0)
{
ret_rset = super.db_stmt.executeQuery(sql);
return ret_rset;
}
page_count = super.record_count / page_size + 1;
if(page < 1)
page = 1;
if(page > page_count)
page = page_count;
super.db_rset = super.db_stmt.executeQuery(sql2);
String as[] = new String[page_size];
super.db_rset.absolute((page - 1) * page_size + 1);
for(int j = 0; j < page_size; j++)
{
as[j] = super.db_rset.getString(1);
if(!super.db_rset.isLast())
super.db_rset.next();
}

String s1 = " " + id + " in ('" + as[0] + "'";
for(int k = 1; k < page_size; k++)
s1 = s1 + " ,'" + as[k] + "'";

s1 = s1 + " ) ";
where = " where " + s1;
setSql();
ret_rset = super.db_stmt.executeQuery(sql);
return ret_rset;
} else
{
return null;
}
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
return null;
}

public boolean setSql()
{
if(tablename == "")
return false;
if(id == "")
return false;
sql = "select";
sql2 = "select";
if(getPam == "")
sql = sql + " * from ";
else
sql = sql + " " + getPam + " from ";
sql2 = sql2 + " " + id + " from ";
sql = sql + " " + tablename;
sql2 = sql2 + " " + tablename;
if(innerjoin != "")
{
sql = sql + " " + innerjoin;
sql2 = sql2 + " " + innerjoin;
}
if(where != "")
{
sql = " " + sql + " " + where;
sql2 = " " + sql2 + " " + where;
}
if(orderby != "")
{
sql = " " + sql + " " + orderby;
sql2 = " " + sql2 + " " + orderby;
}
return true;
}

public boolean setSql(String s)
{
sql = s;
return true;
}

public boolean setSql2(String s)
{
sql2 = s;
return true;
}

public void setId(String s)
{
id = s;
}

public void setTablename(String s)
{
tablename = s;
}

public void setGetPam(String s)
{
getPam = s;
}

public void setInnerjoin(String s)
{
innerjoin = s;
}

public void setWhere(String s)
{
where = s;
}

public void setOrderby(String s)
{
orderby = s;
}

public String getSql()
{
return sql;
}

public String getSql2()
{
return sql2;
}

public void setPage(int i)
{
page = i;
}

public int getPage_count()
{
return page_count;
}

public void setPage_size(int i)
{
page_size = i;
}

private void setPage_desc(String s)
{
page_desc = s;
}

public String getPage_desc()
{
return page_desc;
}


private String sql;
private String sql2;
private String tablename;
private String getPam;
private String innerjoin;
private String where;
private String orderby;
private String id;
private int page_count;
private int page;
private int page_size;
private ResultSet ret_rset;
private String page_desc;
}
lgs6715 2002-11-06
  • 打赏
  • 举报
回复
呵呵,楼主能不能给我个分页的类
和数据库连接的类呀
本人刚刚出道,很多类都不熟悉,编起来太困难,能不能给我参考参考??
qq:64990997
wdllove 2002-11-06
  • 打赏
  • 举报
回复
super.db_stmt = super.db_conn.createStatement(1004,1007);

在分页里是这么联的数据库,但
super.db_stmt.close()
or
super.db_conn.close()
出错,为什么呀
zxhong 2002-11-06
  • 打赏
  • 举报
回复
如果分页的类里没有
数据库的连接
是不需要关闭的
如果有
连接.close()就可以了
wdllove 2002-11-06
  • 打赏
  • 举报
回复

super.db_stmt = super.db_conn.createStatement(1004,1007);

在分页里是这么用联数据库的类的,但
super.db_stmt.close()
or
super.db_conn.close()
出错,为什么呀
wdllove 2002-11-05
  • 打赏
  • 举报
回复
不是我在程序里的名字是不page,不能是名字的问题


to :Kylix_NOW(Kylix_NOW)你的回答是什么意思
Kylix_NOW 2002-11-05
  • 打赏
  • 举报
回复
,<jsp use id=sqlbean session=page>
hxgui 2002-11-05
  • 打赏
  • 举报
回复
你能不能把page换成其它的名字在试试?我猜是名字冲突了。
wdllove 2002-11-05
  • 打赏
  • 举报
回复
我觉得其实没那么麻烦,还是我没说明白,我只要在一个引用另一个类后,再关最它不行吗?请各位指教

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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