在eclipse中访问数据库时提示不能加载驱动,但用命令方式运行又可以,请问是什么原因?
import java.sql.*;
class select
{
public static void main(String args[])
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(Exception e)
{
System.out.println("无法载入JDBC驱动程序");
}
try
{
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ebook","sa","");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select * from users");//执行SQL语句
while (rs.next())
{
System.out.println(rs.getString(1)+rs.getString(2));
}
con.close();
rs.close();
cmd.close();
}
catch(SQLException e)
{
System.out.println("SQL异常");
}
}
}