0

在这里,我正在使用 weblogic 服务器和 oracle 数据库使用 type3 驱动程序进行数据库连接。

我在运行代码时遇到了这个错误

E:\abhishek\D drive\abhishek\advance\jdbc>java Type3oracle
Exception in thread "main" java.sql.SQLException: getConnection, Exception = Une
xpected Exception
        at weblogic.jdbc.rmi.RMIWrapperImpl.invocationExceptionHandler(RMIWrappe
rImpl.java:102)
        at weblogic.jdbc.rmi.Driver.connect(Driver.java:182)
        at Type3oracle.main(Type3oracle.java:21)
Caused by: weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception
        at weblogic.jdbc.common.internal.RmiDataSource_1030_WLStub.getConnection
(Unknown Source)
        at weblogic.jdbc.rmi.Driver.connect(Driver.java:168)
        ... 1 more
Caused by: java.rmi.UnmarshalException: Could not unmarshal method ID; nested ex
ception is:
        java.rmi.UnmarshalException: Method not found: 'createQueryObject(Ljava.
lang.Class<LT;>;)'
        at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
        at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:348)
        at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:259)
        ... 3 more
Caused by: java.rmi.UnmarshalException: Method not found: 'createQueryObject(Lja
va.lang.Class<LT;>;)'
        at weblogic.rmi.internal.MethodDescriptor.getCanonical(MethodDescriptor.
java:197)
        at weblogic.rjvm.MsgAbbrevInputStream.getRuntimeMethodDescriptor(MsgAbbr
evInputStream.java:495)
        at weblogic.rmi.internal.BasicServerRef.dispatch(BasicServerRef.java:269
)
        at weblogic.rmi.cluster.ClusterableServerRef.dispatch(ClusterableServerR
ef.java:242)
        at weblogic.rjvm.RJVMImpl.dispatchRequest(RJVMImpl.java:1135)
        at weblogic.rjvm.RJVMImpl.dispatch(RJVMImpl.java:1017)
        at weblogic.rjvm.ConnectionManagerServer.handleRJVM(ConnectionManagerSer
ver.java:240)
        at weblogic.rjvm.ConnectionManager.dispatch(ConnectionManager.java:882)
        at weblogic.rjvm.MsgAbbrevJVMConnection.dispatch(MsgAbbrevJVMConnection.
java:453)
        at weblogic.rjvm.t3.MuxableSocketT3.dispatch(MuxableSocketT3.java:322)
        at weblogic.socket.AbstractMuxableSocket.dispatch(AbstractMuxableSocket.
java:394)
        at weblogic.socket.NTSocketMuxer.processSockets(NTSocketMuxer.java:105)
        at weblogic.socket.SocketReaderRequest.run(SocketReaderRequest.java:29)
        at weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:
42)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:145)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:117)

这是我的代码

import java.sql.*;
import java.util.*;
//weblogic.jar must be in the classpath and datasource with the specified name must be created and deployed and application server must be running


//type 3 driver


class Type3oracle
{
public static void main(String args[])throws Exception
{
Driver mydriver=(Driver)Class.forName("weblogic.jdbc.rmi.Driver").newInstance();

String url= "jdbc:weblogic:rmi";

Properties props =new Properties();
props.put("weblogic.server.url","t3://localhost:7001");
props.put("weblogic.jdbc.datasource","type3oracle");
//type3oracle is jndi name
Connection con=  mydriver.connect(url,props);
Statement stmt = con.createStatement();
ResultSet rset=stmt.executeQuery("select * from student1");
while(rset.next())
{
System.out.println(rset.getString(1));
}

}
}

请帮助我,我想运行这个程序来连接到数据库 xe 中存在的我的表。

4

1 回答 1

0

使用 JNDI 查找数据源,然后远程 getConnection(),这将为您提供 type3 连接。

于 2013-09-10T11:48:02.403 回答