分类:
2008-05-30 15:13:41
package puyue;
import java.sql.*;
import java.io.*;
import java.util.*;
public class accesslink{
private String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};dbq=e:\\java\\puyue.mdb";
ResultSet rec;
public accesslink()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e){
System.err.print("类加载错误"+e.getMessage());
}
}
public ResultSet executequery(String strsql)
{
rec=null;
try
{
Connection c=DriverManager.getConnection(url);
Statement s=c.createStatement();
rec=s.executeQuery(strsql);
while (rec.next()) {
System.out.println(rec.getString(3));
}
rec.close();
}
catch(SQLException e)
{
System.err.print("数据库连接错误"+e.getMessage());
}
return rec;
}
public static void main(String[] args)
{
accesslink ss=new accesslink() ;
ss.executequery("select * from user") ;
}
}