自认为学了JAVA 也有一段时间了,JDBC对我来说应该还算是可以理解了。但是,今天碰到的问题真的不能让我理解,麻烦高手指点下。我们工作室的人做了一个小东西,我拿来看下,是用myeclipse开发的,我把工程导入到了我的IDE中,然后,把他的数据库链接类的密码改成我的了,结果运行链接数据库是显示“sa登陆失败”!我的项目都能正常运行,这个就不能,我用debug调试了下,连接类中的password传到DriverManager里面时就变成了原来的密码了,原来的是1.这是很让我郁闷的,根本不知道怎么回事,大家可以看下具体的程序。
Conn.java文件:数据库链接类。
public class Conn {
   public Connection con=null;
   private static String ClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
   private static String URL="jdbc:sqlserver://localhost:1433;DataBaseName=luntan";
   private static String User="sa";
   private static String password="sa5221987";
   
public static  Connection getConnection() throws InstantiationException, IllegalAccessException {
  Connection con = null;     try {
     Class.forName(ClassName);
      
     con = DriverManager.getConnection( URL,User, password);     } catch (ClassNotFoundException e) {
     // TODO 自动生成 catch 块
     e.printStackTrace();
    } catch (SQLException e) {
     // TODO 自动生成 catch 块
     e.printStackTrace();
    }
   return con;   }
}DriverManager类的getConnection()方法:
 public static Connection getConnection(String url, 
String user, String password) throws SQLException {
        java.util.Properties info = new java.util.Properties();
//这里的password就不是我在Conn文件中的值了,这是怎么回事,正常不是应该直接就可以传递到这里吗???debug中他的是“1”(这个值是原来的password,但是现在我改了)。
        // Gets the classloader of the code that called this method, may 
// be null.
ClassLoader callerCL = DriverManager.getCallerClassLoader(); if (user != null) {
    info.put("user", user);
}
if (password != null) {
    info.put("password", password);
}        return (getConnection(url, info, callerCL));
    }