EJB常见错误

来源:互联网 发布:索尼签约网络经销商 编辑:程序博客网 时间:2024/05/22 11:43

最近在研究EJB,被一个问题苦恼了3天,做好一个数据库连接池后,添加了一个连接。

接着做了一个简单的客户端来测试:代码如下:

 

 

  1. package com.client; 
  2. import javax.sql.DataSource; 
  3. import java.sql.Connection; import java.sql.ResultSet; 
  4. import java.sql.PreparedStatement; import java.sql.Statement; 
  5. import java.util.Hashtable; 
  6. import java.rmi.*; 
  7. import javax.naming.*; 
  8. public class ConnectionPoolTest {
  9.  /** * @param args */ 
  10. public static void main(String[] args) { // TODO 自动生成方法存根 
  11. Hashtable ht = new Hashtable();
  12.  ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
  13.  ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); 
  14. try { 
  15.     Context context = new InitialContext(ht); 
  16.     javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("myJNDI");
  17.     java.sql.Connection con = ds.getConnection(); 
  18.     java.sql.Statement stat = con.createStatement(); 
  19.     ResultSet rs=stat.executeQuery("select * from Accounts"); 
  20.     while(rs.next()) { 
  21.         System.out.println(rs.getString(2)); 
  22.     } 
  23.     con.close(); 
  24. catch(Exception e) 
  25. e.printStackTrace(); 
  26. }

 结果报异常了 weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception - with nested exception: [java.rmi.UnmarshalException: Could not unmarshal method ID; nested exception is: java.rmi.UnmarshalException: Method not found: 'createArrayOf(Ljava.lang.String;[Ljava.lang.Object;)'] at weblogic.jdbc.rmi.internal.ConnectionImpl_weblogic_jdbc_wrapper_PoolConnection_weblogic_jdbc_sqlserver_SQLServerConnection_816_WLStub.createStatement(Unknown Source) at weblogic.jdbc.rmi.SerialConnection.createStatement(SerialConnection.java:157) at com.client.ConnectionPoolTest.main(ConnectionPoolTest.java:30) > java.sql.SQLException: weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception - with nested exception: [java.rmi.UnmarshalException: Could not unmarshal method ID; nested exception is: java.rmi.UnmarshalException: Method not found: 'createArrayOf(Ljava.lang.String;[Ljava.lang.Object;)'] at weblogic.jdbc.rmi.SerialConnection.createStatement(SerialConnection.java:169) at com.client.ConnectionPoolTest.main(ConnectionPoolTest.java:30 怎么也不知道问题出在哪里了,重装系统也没用。网上也没有解决的办法。

 
最后抱着试试看的心情,将我的1.6的JDK改成了1.4的JDK,结果可以了,接着又试了试1.5的JDK也可以,呵呵,原来是JDK版本问题我用的是Eclips3.1+Weblogic8.1
原创粉丝点击