从weblogic数据源里获取连接的时候抛出了异常如下:Exception in thread "main" java.lang.ClassCastException: weblogic.jdbc.common.internal.ConnectionEnv cannot be cast to java.io.Serializable
        at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2266)
        at weblogic.utils.io.ObjectStreamClass.writeFields(ObjectStreamClass.java:413)
        at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:235)
        at weblogic.corba.utils.ValueHandlerImpl.writeValueData(ValueHandlerImpl.java:225)
        at weblogic.corba.utils.ValueHandlerImpl.writeValue(ValueHandlerImpl.java:182)
        at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1963)
        at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:2001)
        at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2266)
        at weblogic.jdbc.common.internal.RmiDataSource_WLSkel.invoke(Unknown Source)
        at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589)
        at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
        at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
        at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473)
        at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)这里是我的代码:
import java.sql.*;
import java.util.Hashtable;
import javax.naming.*;
import javax.sql.*;public class DataSourceTest {
    public DataSourceTest(){}    public static void main(String[] args){
        DataSource ds = null;
        Context ctx = null;
        Connection myConn = null;
        Statement myStatement = null;
        ResultSet myResultSet = null;
        
        try{
            Hashtable pro = new Hashtable();
            pro.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            pro.put(Context.PROVIDER_URL, "t3://localhost:7001");
            pro.put(Context.SECURITY_PRINCIPAL, "weblogic");
            pro.put(Context.SECURITY_CREDENTIALS, "weblogic1");
            ctx = new InitialContext(pro);
            ds = (javax.sql.DataSource)ctx.lookup("mysql_ds");
        }catch(Exception E){
            System.out.println("Init Error: " + E);
        }        try{
            myConn = ds.getConnection();  
            myStatement = myConn.createStatement();  
            myResultSet = myStatement.executeQuery("select * from recordings");
            while(myResultSet.next()){
                System.out.println("the name is " + myResultSet.getString("StoreCity"));
            }
            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());
            }
        }
    }
}
builderpath:mysql-connector-java-5.1.13-bin.jar
            weblogic.jar
            wlclient.jarweblogic10.3.3
mysql5.1希望高手帮帮我啊....搞了好久都没成功

解决方案 »

  1.   

    Exception in thread "main" java.lang.ClassCastException: weblogic.jdbc.common.internal.ConnectionEnv cannot be cast to java.io.Serializable跟代码没有关系,估计是包的问题。换个weblogic的包试试看。I would suggest you to remove the wlClient.jar from the classpath.
    Also make sure that there are no other jar files related to weblogic in the classpath.
    Add weblogic.jar in the classpath and make sure that this weblogic.jar is the same jar that is in the weblogic server classpath.This happens because of the difference in the jar used by the Client JVM and server JVM.
      

  2.   

    我装的是10.3.3的weblogic,只有一个weblogic包..
    请问换其他的可以用吗
      

  3.   

    如果把wlclient.jar去掉,只导入weblogic包也不行..异常如下:
    Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/subject/AbstractSubject
            at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
            at javax.naming.InitialContext.init(InitialContext.java:223)
            at javax.naming.InitialContext.<init>(InitialContext.java:197)
            at DataSourceTest.main(DataSourceTest.java:22)
    Caused by: java.lang.ClassNotFoundException: weblogic.security.subject.AbstractSubject
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            ... 6 more
      

  4.   

    make sure that this weblogic.jar is the same jar that is in the weblogic server classpath.This happens because of the difference in the jar used by the Client JVM and server JVM.网上说,是weblogic的包不一致导致的。
    其他我就不知道了。