连接ACCESS的Javabean编译出错
我的连接ACCESS的Javabean编译时出现如下的错误:
请大家指点一下.
--------------------------------------
C:\> javac dbuitil.java
dbuitil.java:9: 需要 <标识符>
strDirPath = strDirPath.replace ( '\\ ', '/ ');
^
1 错误
--------------------------------------
Javabean文件的代码如下:
package test1;
import java.sql.*;
public class DBUitil
{
String str_driver = "sun.jdbc.odbc.JdbcOdbcDriver ";
String strDirPath = getServletContext().getRealPath( "/ ");
strDirPath = strDirPath.replace ( '\\ ', '/ ');
String strurl= "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ= "+strDirPath+ "data/test.mdb ";
Connection conn = null;
ResultSet rs = null;
public DBUitil()
{
try
{
Class.forName(str_driver);
}
catch(
java.lang.ClassNotFoundException e)
{
System.err.println( "testJDBC(): " + e.getMessage());
}
}
public ResultSet executeQuery(String testJDBC)
{
rs = null;
try
{
conn = DriverManager.getConnection(strurl);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(testJDBC);
}
catch(
SQLException ex)
{
System.err.println( "aq.executeQuery: " + ex.getMessage());
}
return rs;
}
}
------解决方案--------------------去掉strDirPath = strDirPath.replace ( '\\ ', '/ ');
------解决方案--------------------DBUtil只是一个数据库工具类,它里面怎么可以调用getServletContext()方法呢?
它又不是一个Servlet