java 关于Statement关闭的一个比较简单的问题!
importjava.beans.Statement;importjava.sql.Connection;importjava.sql.DriverManager;imp...
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class dbbean {
private Connection con ;
public dbbean()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Connection getConnection() throws SQLException
{
return con=DriverManager.getConnection("jdbc:oracle:thin:@xxxx:1521:xxxx", "xxxx",
"xxxx");
}
protected void closeConnection(Connection conn)
{
if(conn!=null)
{
try
{
conn.close();
conn=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
protected void closeStatement(Statement stmt)
{
if(stmt!=null)
{
try
{
stmt.close();////就是这句提示没有没有close 方法
stmt=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
/**
* 关闭PreparedStatement对象。
*/
protected void closePreparedStatement(PreparedStatement pstmt)
{
if(pstmt!=null)
{
try
{
pstmt.close();
pstmt=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
/**
* 关闭ResultSet对象。
*/
protected void closeResultSet(ResultSet rs)
{
if(rs!=null)
{
try
{
rs.close();
rs=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
} 展开
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
public class dbbean {
private Connection con ;
public dbbean()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Connection getConnection() throws SQLException
{
return con=DriverManager.getConnection("jdbc:oracle:thin:@xxxx:1521:xxxx", "xxxx",
"xxxx");
}
protected void closeConnection(Connection conn)
{
if(conn!=null)
{
try
{
conn.close();
conn=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
protected void closeStatement(Statement stmt)
{
if(stmt!=null)
{
try
{
stmt.close();////就是这句提示没有没有close 方法
stmt=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
/**
* 关闭PreparedStatement对象。
*/
protected void closePreparedStatement(PreparedStatement pstmt)
{
if(pstmt!=null)
{
try
{
pstmt.close();
pstmt=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
/**
* 关闭ResultSet对象。
*/
protected void closeResultSet(ResultSet rs)
{
if(rs!=null)
{
try
{
rs.close();
rs=null;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询