Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » Other DB  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 一个很菜鸟的关于weblogic和JDataStore的问题
Hughes





发贴: 1
积分: 0
于 2004-12-01 16:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
本人是个菜鸟,刚学不久,日前遇到一个问题怎么也搞不懂,还请大虾帮忙。
按书上写了一个使用Jdbc的例子,但怎么也调不通。faint!
数据库:Jbuilder9自带JDataStore.
weblogic版本:8.1
连接池已经设定好
Name:JDataStorePool
server:myserver
DataSouce:
Name:JDataStoreDataSource
JNDI Name:JDataStoreDataSource
PoolName:JDataStorePool
target:myserver
Weblogic启动后,JDataStore显示已经连接成功。

但一下程序(按照书上打的,怎么也跳不通,晕)
package jdbctest1;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import java.sql.Connection;

public class test {
public test() {
}
private static Context getInitialContext() throws Exception
{
String url="t3://localhost:7001";
String user="system";
String password="security";
Properties properties=null;
try{
properties=new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLIntialContextFactory");
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("InitialContext Error:"+e);
throw e;
}
}

public static void main(String argv[]){
DataSource ds=null;
Context ctx=null;
Connection myconn=null;
try{
ctx=getInitialContext();
//ctx=new InitialContext();
ds=(javax.sql.DataSource)ctx.lookup("JDataStoreDataSource");
}
catch(Exception E)
{
System.out.println("Init Error:"+E);
}
Statement myStatement=null;
ResultSet myResultSet=null;
Connection myConn=null;
try{
myConn=ds.getConnection();
myStatement=myConn.createStatement();
myResultSet=myStatement.executeQuery("select full_name from employee");
while(myResultSet.next())
{
System.out.println("the employee full 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());
}
}
}
}

报错:
javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLIntialContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLIntialContextFactory]




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923