JavaBean里有如下的方法
public ResultSet executeQuery( )
{
try
{
Class.forName( driver ) ; //注册驱动程序用何类包
}
catch ( java.lang.ClassNotFoundException e )
{
System.err.println( "Error at JavaBean Constructor DBConn.DBConn():"
+ e.getMessage() + "疑为注册驱动类包错误" ) ;
//输出本Bean构造函数处的错误信息
}
ResultSet rs = null ; //初始化清空查询结果集
try
{
conn = DriverManager.getConnection( url , user , password ) ; //创建数据库连接对象
stmt = conn.createStatement() ;
rs = stmt.executeQuery("SELECT NEWPDCTADV_ID,NEWPDCTADV_TITLE FROM NEWPRODUCTSADV WHERE IF_ShowOn = '1';") ;
}
catch ( SQLException ex )
{
System.err.println( "Error at JavaBean DBConn.executeQuery():"
+ ex.getMessage() + "疑为数据库查询错误" ) ;
//捕获并输出错误在于本javabean的executeQuery()方法
}
return rs ;
}