急,急,急 关于weblgoic 测试程序连接数据库的错误提示帐号错误
各位高手你们好:
我照着书上的源代码写的程序,关于测试通过应用服务器连接后台数据库时,编译都没有问题,但运行时去出现帐号错误。我的weblgic已经启动成功,数据源和连接池启动时没有错误.并且配置也没有问题,配置的问题是没有错误的,我测试了很多编。
我的源程序如下:
package jdbc_exe;
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;
public class jdbc
{
public static void main(String[] args) {
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
try {
ctx = getInitialContext();
System.out.println("fdsadfs");
ds = (javax.sql.DataSource)ctx.lookup("MSSQLServerConnectionPool");
}
catch (Exception e) {
System.out.println("Init Error jkljk " + e);
}
Statement myStatement = null;
ResultSet myResultSet = null;
try{
myConn = ds.getConnection();
myStatement = myConn.createStatement();
myResultSet = myStatement.executeQuery("select * from all_fbdw");
while(myResultSet.next())
{
System.out.println("The all_fbdw name is " + myResultSet.getString("full_name"));
}
myResultSet.close();
}catch(SQLException e){
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
finally{
try{
if(myStatement != null){
myStatement.close();
}
if(myConn != null){
myConn.close();
}
}catch(SQLException e){
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
}
}
private static Context getInitialContext() throws Exception{
String url = "t3://lht:7001";
String user = "sa";
String password = null;
Properties properties = null;
try{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL,url);
if(user != null){
properties.put(Context.SECURITY_PRINCIPAL,user);
properties.put(Context.SECURITY_CREDENTIALS,password == null ? "":password);
}
return new InitialContext(properties);
}catch(Exception e){
throw e;
}
}
}
运行的错误如下:
Init Error jkljk javax.naming.AuthenticationException [Root exception is java.lang.SecurityException: User: sa, failed to be authenticated.
当我把连接池的数据源名字改了之后,变成数据源名字是oracle的时候也提示错误,错误如下:
Init Error jkljk javax.naming.AuthenticationException [Root exception is java.lang.SecurityException: User: nys, failed to be authenticated.
这个问题困扰了很久,不知道哪位高手看了之后能不能给一个正确的解释
关于这个帐号的正确的解释是什么,