java.lang.ClassCastException: weblogic.jdbc.common.internal.ConnectionEnv cannot
在weblogic连接mysql数据库出现了下面问题,谢谢
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)
源代码:
package c;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class jdbc1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DataSource ds = null;
Context ctx = null;
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
Hashtable p = new Hashtable();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
ctx = new InitialContext(p);
// String test = "MysqlWeblogic1";
ds = (DataSource) ctx.lookup("MysqlWeblogic1");
con = ds.getConnection();
stmt = con.createStatement();
rs = stmt.executeQuery("select * from book");
while (rs.next())
System.out.print(rs.getString("bookName"));
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs == null)
rs.close();
if (stmt == null)
stmt.close();
if (con == null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}