日期:2014-05-20  浏览次数:20790 次

eclipse配置构建路径顺序问题
我加入weblogic10的包weblogic.jar和wlclient.jar的时候当先加入前者后加入后者的时候可以顺利执行程序,当先加入后者的时候就报错了程序和错误如下:还有当以前学jdbcpool的时候加入weblogic.jar必须从F:\BEA\....\LIB路径下加载否者就不对,真奇怪
import javax.transaction.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.naming.*;
import javax.sql.DataSource;
import java.util.Properties;

public class JTADemo1{
public static Context getContext() throws Exception{
Properties p=new Properties();
Context ctx=null;
try{
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
ctx=new InitialContext(p);
}
catch(Exception e){
throw e;
}
return ctx;
}
public static UserTransaction getUserTransaction() throws Exception{
Context ctx=null;
UserTransaction tx=null;
try{
ctx=getContext();
tx=(UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
}
catch(Exception e){
throw e;
}
return tx;
}
public static void main(String ar[]){
Connection conn=null;
Statement stmt=null;
UserTransaction tx=null;
DataSource ds=null;
Context ctx=null;
String sql1="select * from customers";
try{
ctx=getContext();
tx=getUserTransaction();
tx.begin();
System.out.println("dssdsdds");
ds=(javax.sql.DataSource)ctx.lookup("MysqlDataSource");
conn=ds.getConnection();
System.out.println("sss");
stmt=conn.createStatement();

ResultSet e=stmt.executeQuery(sql1);
while(e.next()){
System.out.println(e.getString(1));

}
tx.commit();
System.out.println("事务被成功提交");
}
catch(Exception e){
try{tx.rollback();}
catch(Exception e1){}
e.printStackTrace();
System.out.println("事务发生错误,事务被取消");
}
}
}


dssdsdds
java.lang.ClassCastException: weblogic.transaction.internal.ServerTransactionImpl
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2253)
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:1957)
at weblogic.iiop.IIOPOutputStream.write_value(IIOPOutputStream.java:1992)
at weblogic.iiop.IIOPOutputStream.writeObject(IIOPOutputStream.java:2253)
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:224)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:479)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:475)
at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:59)
at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:1016)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:172)
事务发生错误,事务被取消



------解决方案--------------------
路径不对,肯定要报错的!
------解决方案--------------------
在项目中,进行查询weblogic.transaction.internal.ServerTransactionImpl 或者weblogic.transaction.internal看是不是,有两个包中有呀,如果是这样的话,就是说你的包冲突啦,明白吗,因为你在导入时,WEB SERVER加载的不同,可能产生的效果也就不同啦,优先级就不同啦!