第二部分中的server.xml中的
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databasename=nextep</value>
我写错了,应是:
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databasename=mydatabase</value>
(我的程序中没有写错,是刚才的帖子写错了:-)).
依然等待中.......
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databasename=nextep</value>
我写错了,应是:
<name>url</name>
<value>jdbc:microsoft:sqlserver://localhost:1433;databasename=mydatabase</value>
(我的程序中没有写错,是刚才的帖子写错了:-)).
依然等待中.......
注意点:
1、配好连接池后,如果weblogic能够成功启动,说明配置成功!
2、可以先把部分语句注释掉,看看问题到底出现在哪步,然后针对问题解决。Context ctx = (Context)initCtx.lookup("java:comp/env"); DataSource ds = (DataSource)ctx.lookup("jdbc/SqlServerDB"); Connection con = ds.getConnection(); Statement st = con.createStatement();
private Context getInitialContext() throws Exception {
String url = "t3://wangqiang:7001";
String user = null;
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) {
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
}
.....
try {
Context ctx = getInitialContext(); Object h = ctx.lookup("jdbc/SqlServerDB");
不要写这个
Context ctx = (Context)initCtx.lookup("java:comp/env");
我的tomcat能找到我的驱动。
to:gaosikai()
好象配置没有问题,问题出在Connection con = ds.getConnection();上。
在.java中相关代码为:
Context initCtx = new InitialContext();
Context ctx = (Context)initCtx.lookup("java:comp/env");
DataSource ds = (DataSource)ctx.lookup("jdbc/SqlServerDB");
提示错误信息:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial后来我在第二行加上一句:
initCtx.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
提示出错信息为:
javax.naming.NameNotFoundException: java:comp/env
把此行去掉,提示出错信息为:
javax.naming.NameNotFoundException: jdbc/SqlServerDB