我综合了only you、wind520的方法,用如下程序测试(采用JCreatePro),我已经把delphibbs.mdb文件放在[red]TestAccess.class及TestAccess.java[/red]文件的同一目录下,但都不行,编译错误在程序下面,请指教:
import java.sql.*;
public class TestAccess
{
public void SearchRooms()
{
Connection con;
Statement stmt;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url = "jdbc
dbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E://delphibbs.mdb";
String url="jdbc
dbc:driver={Microsoft Access Driver (*.mdb)};dbq=";
url=url+application.getRealPath("delphibbs.mdb");
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from rooms");
while (rs.next())
{
String str=rs.getString("room");
System.out.print(str+"/n");
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args)
{
TestAccess ta=new TestAccess();
ta.SearchRooms();
//System.out.println("Hello World!");
}
}
C:/Program Files/Xinox Software/JCreator Pro/MyProjects/TestAccess/TestAccess.java:12: cannot resolve symbol
symbol : variable application
location: class TestAccess
url=url+application.getRealPath("delphibbs.mdb");
^