How to load changes made in native java classes?

Question:

hello

I'm trying to run a jar file, replacing some original java interfaces for connecting to the database, changing the setBoolean method to take an object as a parameter.

Original :

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

My change:

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

My changes were made in the PreparedStatement class so that my changes are called, when starting the application I'm using the command:

java -Xbootclasspath/p:C:/Users/elizio/Desktop/safepdv700/safepdv700/src/main/java -jar safepdv.jar

By using "-verbose:class" I can verify that it loads the class with my changes.

However, when setBoolean is called by the application, it doesn't find the method, returning:

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.ConfiguracaoController.updateCS(ConfiguracaoController.java:613)
    at com.t2tierp.pafecf.view.MovimentoAberto.validaCamposLogin(MovimentoAberto.java:448)
    at com.t2tierp.pafecf.view.MovimentoAberto.passwordTextSenhaUsuarioActionPerformed(MovimentoAberto.java:403)
    at com.t2tierp.pafecf.view.MovimentoAberto.access$200(MovimentoAberto.java:22)
    at com.t2tierp.pafecf.view.MovimentoAberto$4.actionPerformed(MovimentoAberto.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)

Changes made both to the Java interface and also to the Mysql-Connector source code are in this repository:

https://github.com/jackelinesantos/PreparedStatementChanged/tree/master/mysql-5.1.38/src/com/mysql/jdbc

What should I do so that my method is called instead of the original one since my class is being loaded according to the log?

Answer:

It doesn't find the method simply because its class doesn't implement the method declared in the java.sql.PreparedStatement interface which is the void setBoolean(int parameterIndex, boolean x ) method see that the boolean is the primitive and not the Boolean object, so in this if you didn't implement the interface method, you just created a new one. So when java tries to find a class with the implementation of setboolean with primitive it doesn't find it and launches the

java.lang.NoSuchMethodError:

Scroll to Top