急急急,关于用jb8测试通过weblgoic 连接数据库的错误

lhtjava 2003-09-10 12:31:11
各位高手你们好:

我照着书上的源代码写的程序,关于测试通过应用服务器连接后台数据库时,编译都没有问题,但运行时去出现帐号错误。我的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.

这个问题困扰了很久,不知道哪位高手看了之后能不能给一个正确的解释
关于这个帐号的正确的解释是什么.



...全文
58 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhx_232 2003-09-11
  • 打赏
  • 举报
回复
就是这样啦,异常明明就说明是这样的啦。
properties.put(Context.SECURITY_CREDENTIALS,password == null ? "":password);
你的password为空,那么password="",当然不能通过认证啦。
user和password应该是weblogic启动时候的用户名和密码,而不是数据库的用户名和密码,因为你调用weblogic的JNDI。
如果你是放在weblogic下面直接运行的话,这些东西都没有必要要了。
lhtjava 2003-09-11
  • 打赏
  • 举报
回复
哦,我在试一下吧,如果真可以我可真的要好好谢谢你了
lhtjava 2003-09-10
  • 打赏
  • 举报
回复
好像不是,我也试了可是还是不行,有没有别的招啊
zhx_232 2003-09-10
  • 打赏
  • 举报
回复
getInitialContext()中的User和password是weblogic启动的user和password,如:system,12345678。weblogic的密码至少8位呢

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧