最近在研究EJB,被一个问题苦恼了3天,做好一个数据库连接池后,添加了一个连接。
接着做了一个简单的客户端来测试:代码如下:
- package com.client;
- import javax.sql.DataSource;
- import java.sql.Connection; import java.sql.ResultSet;
- import java.sql.PreparedStatement; import java.sql.Statement;
- import java.util.Hashtable;
- import java.rmi.*;
- import javax.naming.*;
- public class ConnectionPoolTest {
- /** * @param args */
- public static void main(String[] args) { // TODO 自动生成方法存根
- Hashtable ht = new Hashtable();
- ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
- ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
- try {
- Context context = new InitialContext(ht);
- javax.sql.DataSource ds = (javax.sql.DataSource)context.lookup("myJNDI");
- java.sql.Connection con = ds.getConnection();
- java.sql.Statement stat = con.createStatement();
- ResultSet rs=stat.executeQuery("select * from Accounts");
- while(rs.next()) {
- System.out.println(rs.getString(2));
- }
- con.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- }
结果报异常了 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