jsp中使用<jsp:useBean>,但一定要把bean放进包内,才能正常运行,这是为什么?实在是想不通。
bean文件我已正确放入文件夹中。C:\ProgramFiles\ApacheSoftwareFoundation\Tomcat5.0\webapps\ROOT\WEB-...
bean文件我已正确放入文件夹中。
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes
<jsp:useBean id="bb" scope="page" class="firm.firm" />
package firm;
import java.sql.*;
public class firm{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:db2";
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public firm(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("firm():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql){
stmt=null;
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
public void closeStmt(){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
} 展开
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT\WEB-INF\classes
<jsp:useBean id="bb" scope="page" class="firm.firm" />
package firm;
import java.sql.*;
public class firm{
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr="jdbc:odbc:db2";
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public firm(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("firm():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql){
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql){
stmt=null;
rs=null;
try{
conn=DriverManager.getConnection(sConnStr);
stmt=conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}catch(SQLException ex){
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
public void closeStmt(){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
public void closeConn(){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
} 展开
1个回答
2013-04-06
展开全部
java 的规定~~~~~~~~~~~~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询