连接access数据库bean的问题,等待高手
package news;
import java.sql.*;
public class conn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver ";
String strDirPath = application.getRealPath( "/ ");
String strDirPath1 = strDirPath.substring(0,strDirPath.lastIndexOf( '\\ '))+ "\\ ";
String sConnStr = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ= "+strDirPath1+ "samples//news.mdb ";
Connection connect = null;
ResultSet rs = null;
public conn() {
try {
Class.forName(sDBDriver);
}
catch(
java.lang.ClassNotFoundException e) {
System.err.println( e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql);
}
catch(
SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
public int executeUpdate(String sql) {
int result = 0;
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return result;
}
}
这个bean要在jsp中调用,为什么编译时
String strDirPath = application.getRealPath( "/ ");
提示application有问题?谢谢
------解决方案--------------------application 这是什么对象
你的意思应该是在bean里面调用jsp的内置对象 application ?
这样不可行的