自认为学了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));
}
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));
}
解决方案 »
- struts2问题..请高手指教..
- Sturts标签的问题
- 关于org.springframework.beans.factory.BeanFactory的getBean(),报NullPointerException
- 分享一点个人关于Ioc容器实现的探讨!渴望得到大家的指点!真诚感谢!
- 上海某软件有限公司招聘WEB,JAVA工程师(紧急)
- EJB
- web service 客户端能不能 不导入服务端wdsl文件
- 急盼高手:struts1.2中ActionErrors的问题!
- 在java中直接中断程序用什么呢?
- 请教,如何在JSP中嵌入JAVA Applet 在线等待。
- Hibernate 批量_一对多_级联_删除
- 启动tomcat时mysql连接不上服务器
这个是干什么的啊
的确强悍!