conn关闭出错问题!在线等!!!(就这100分了!)
我们刚学习编程,老师给了一个编写了一个数据库链接操作的类(如下)。我在jsp调用的时候如何才能关闭conn链接?请大家赐教!我是初学的还不大懂!谢谢大家了!
页面引用:
<%
conn db = new conn();
ResultSet rs = db.Query( "* ", "表 ");
while(rs.next()){
}
rs.close();
db.con.close();
%>
连接数据库的类:
package
db.con.close();
package airinb2b;
import java.sql.*;
import java.io.*;
import java.util.*;
public class conn //定义类名
{
java.sql.Connection con;
Statement st;
ResultSet rs;
public conn()
{
try{ //容错
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
con = DriverManager.getConnection( "jdbc:odbc:airinb2b ", "sa ", "tytymnty110110 ");
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(Exception e){}
}
/**查询记录的方法*/
public ResultSet Query(String biao,String table,String tiaojian)
{
try{//必要的容错
String select = "select "+biao+ " from "+table+ " where 1=1 "+tiaojian;
rs = st.executeQuery(select);//查询结果的显示
}
catch(Exception e)
{
System.out.print(e.toString());//容错语句
}
return rs;
}
public int count(String table)
{
int n=0;
try{
String select = "select * from "+table;
rs = st.executeQuery(select);//查询结果的显示
while(rs.next()){ n = rs.getRow();}
}
catch(Exception e)
{
System.out.print(e.toString());//容错语句
&nbs