B4J Question SD_SQL error - java.lang.reflect.InvocationTargetException

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hello, I kept getting this Error when trying to insert into MYSQL Database (Using WAMP). The First Item is inserted then, it crashes

Error:
Waiting for debugger to connect...
Program started.
---------- NorthWind Database (MySQL) ----------
connected
Error occurred on line: 41 (SD_SQL)
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4j.example.sd_sql._execnonquery(sd_sql.java:85)
    at b4j.example.main._appstart(main.java:117)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.start(main.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NullPointerException
    at b4j.example.sd_sql.execnonquery(sd_sql.java:266)
    ... 31 more


HERE IS MY CODE
CODE:
Log("---------- NorthWind Database (MySQL) ----------")
    MYSQL.Initialize(Me,"MYSQL", "com.mysql.jdbc.Driver", $"jdbc:mysql://${MyLocation}/ebvotes?useSSL=false"$,  MyUsername, MyPassword)
    
    
    Dim myvotelist As List
    myvotelist.Initialize
    myvotelist.AddAll( Array As String("A","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"))
    
    Dim voteid As String = "xesj"
    Dim deviceid As String = "test12"
    Dim timeofvote As String = "12:00:01"

    For Each j As String In myvotelist
        Log("..." & j)
        MYSQL.ExecNonQuery($"INSERT INTO tblvotes (id, votesname, voteid, deviceid, timeofvote) VALUES (NULL, '${j}', '${voteid}', '${deviceid}', '${timeofvote}')"$)
    Next
    
    Log("Done")

End Sub

Sub MainForm_Resize (Width As Double, Height As Double)

End Sub


'Connected to MySQL Server
Sub MySQL_Ready (Success As Boolean)   
    If Success Then
        Log("Database Connected")
    End If

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top