如何加载在本机java类中进行的修改?

时间:2017-07-06 12:03:15

标签: java command-line prepared-statement

您好,

我试图执行一个jar文件,覆盖一些java原始接口以连接数据库,更改方法setBoolean以接收像参数这样的对象。

这是原始界面方法:

void setBoolean(int parameterIndex, boolean x) throws SQLException;

这是我的改变:

void setBoolean(int parameterIndex, Boolean x) throws SQLException;

我的更改是在接口java.sql.PreparedStatement上进行的。为了调用我的更改,当我启动应用程序时,我使用命令:

java -verbose:class -Xbootclasspath/p:C:/Users/user/Desktop/myproject/src/main/java -jar safepdv.jar

使用命令" -verbose:class"我可以验证是否正在加载包含我的更改的类。

但是,当应用程序调用方法setBoolean时,他还没有成立,我的回报是:

Exception in thread "AWT-EventQueue-0" [Loaded java.lang.Throwable$WrappedPrintStream from C:\Program Files\Java\jre1.8.0_91\lib\rt.jar]
java.lang.NoSuchMethodError: java.sql.PreparedStatement.setBoolean(IZ)V
    at com.t2tierp.pafecf.controller.ConfigurationController.updateCS(ConfigurationController.java:613)
    at com.t2tierp.pafecf.view.OpenMoviment.validaCamposLogin(OpenMoviment.java:448)
    at com.t2tierp.pafecf.view.OpenMoviment.passwordTextSenhaUsuarioActionPerformed(OpenMoviment.java:403)
    at com.t2tierp.pafecf.view.OpenMoviment.access$200(OpenMoviment.java:22)
    at com.t2tierp.pafecf.view.OpenMoviment$4.actionPerformed(OpenMoviment.java:240)
    at javax.swing.JTextField.fireActionPerformed(Unknown Source)
    at javax.swing.JTextField.postActionEvent(Unknown Source)
    at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
    at javax.swing.SwingUtilities.notifyAction(Unknown Source)
    at javax.swing.JComponent.processKeyBinding(Unknown Source)
    at javax.swing.JComponent.processKeyBindings(Unknown Source)
    at javax.swing.JComponent.processKeyEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
    at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.WaitDispatchSupport$2.run(Unknown Source)
    at java.awt.WaitDispatchSupport$4.run(Unknown Source)
    at java.awt.WaitDispatchSupport$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.WaitDispatchSupport.enter(Unknown Source)
    at java.awt.Dialog.show(Unknown Source)
    at java.awt.Component.show(Unknown Source)
    at java.awt.Component.setVisible(Unknown Source)
    at java.awt.Window.setVisible(Unknown Source)
    at java.awt.Dialog.setVisible(Unknown Source)
    at com.t2tierp.pafecf.view.Caixa.verificarMovimentoExistente(Caixa.java:3392)
    at com.t2tierp.pafecf.view.Caixa.<init>(Caixa.java:344)
    at com.t2tierp.pafecf.view.Caixa$41.run(Caixa.java:2393)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

如何才真正调用我的方法而不是原始方法?

1 个答案:

答案 0 :(得分:0)

调用代码仍在尝试将null值传递给旧方法的签名(期望boolean,而不是Boolean)。您需要重新编译调用代码,以便它绑定到新方法签名:要调用的方法签名在编译时是固定的。

另外,请注意PreparedStatement是一个接口 - 更改其定义可能会破坏实现所述接口的所有类。最值得注意的是,每个JDBC驱动程序都包含自己的实现;你必须从源代码重新编译驱动程序才能解决这个问题。

对于调用代码进行反编译并简单地将其修复到传递null的位置,然后重新编译它是可能的,但是很丑陋且不可维护。您可以将其自动化到某一点(想想字节码编辑库),但要点是无法访问源代码,这会导致错误调用,这是一个严重的缺陷。