• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Database connection on android studio using java.

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I am literally following a tutorial word to word from this link - Youtube - MySQL & Android Studio JDBC
What I am trying to do is connect to my database as you might have guessed, and retrieve a simple text from it.

My issue is that once I press on the button, the application just crashes?  I have no idea for what reason.
The only code that changes is the connection part (with my credentials) and what I need to printout. Apart from that, everything is identical...

Could someone help me overcome this issue please?
 
Darius Boteand
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this can help anyone understand the reason, this is the output I have in the logcat:

2021-01-07 15:10:10.390 22070-22070/? I/example.test_0: Not late-enabling -Xcheck:jni (already on)
2021-01-07 15:10:10.426 22070-22070/? I/example.test_0: Unquickening 12 vdex files!
2021-01-07 15:10:10.428 22070-22070/? W/example.test_0: Unexpected CPU variant for X86 using defaults: x86
2021-01-07 15:10:11.080 22070-22070/com.example.test_09 D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-01-07 15:10:11.082 22070-22070/com.example.test_09 D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-01-07 15:10:11.110 22070-22094/com.example.test_09 D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
2021-01-07 15:10:11.114 22070-22094/com.example.test_09 D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
2021-01-07 15:10:11.124 22070-22094/com.example.test_09 D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
2021-01-07 15:10:11.343 22070-22070/com.example.test_09 W/example.test_0: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2021-01-07 15:10:11.343 22070-22070/com.example.test_09 W/example.test_0: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2021-01-07 15:10:11.512 22070-22092/com.example.test_09 D/HostConnection: HostConnection::get() New Host Connection established 0xee7eafd0, tid 22092
2021-01-07 15:10:11.546 22070-22092/com.example.test_09 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2021-01-07 15:10:11.556 22070-22092/com.example.test_09 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-01-07 15:10:11.559 22070-22092/com.example.test_09 D/EGL_emulation: eglCreateContext: 0xee7f8320: maj 3 min 0 rcv 3
2021-01-07 15:10:11.562 22070-22092/com.example.test_09 D/EGL_emulation: eglMakeCurrent: 0xee7f8320: ver 3 0 (tinfo 0xeeb38cd0) (first time)
2021-01-07 15:10:11.591 22070-22092/com.example.test_09 I/Gralloc4: mapper 4.x is not supported
2021-01-07 15:10:11.593 22070-22092/com.example.test_09 D/HostConnection: createUnique: call
2021-01-07 15:10:11.594 22070-22092/com.example.test_09 D/HostConnection: HostConnection::get() New Host Connection established 0xee7f8470, tid 22092
2021-01-07 15:10:11.595 22070-22092/com.example.test_09 D/goldfish-address-space: allocate: Ask for block of size 0x100
2021-01-07 15:10:11.626 22070-22092/com.example.test_09 D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fd4e1000 size 0x2000
2021-01-07 15:10:11.658 22070-22092/com.example.test_09 D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
2021-01-07 15:10:15.301 22070-22099/com.example.test_09 W/example.test_0: Accessing hidden method Ljava/lang/invoke/LambdaMetafactory;->metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; (blacklist, linking, denied)
2021-01-07 15:10:15.306 22070-22099/com.example.test_09 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
   Process: com.example.test_09, PID: 22070
   java.lang.RuntimeException: An error occurred while executing doInBackground()
       at android.os.AsyncTask$4.done(AsyncTask.java:415)
       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
       at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
       at java.util.concurrent.FutureTask.run(FutureTask.java:271)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:923)
    Caused by: java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
       at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.<clinit>(AbandonedConnectionCleanupThread.java:63)
       at java.lang.Class.classForName(Native Method)
       at java.lang.Class.forName(Class.java:454)
       at java.lang.Class.forName(Class.java:379)
       at com.mysql.cj.jdbc.NonRegisteringDriver.<clinit>(NonRegisteringDriver.java:98)
       at java.lang.Class.classForName(Native Method)
       at java.lang.Class.forName(Class.java:454)
       at java.lang.Class.forName(Class.java:379)
       at com.example.test_09.MainActivity$Task.doInBackground(MainActivity.java:50)
       at com.example.test_09.MainActivity$Task.doInBackground(MainActivity.java:37)
       at android.os.AsyncTask$3.call(AsyncTask.java:394)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305) 
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
       at java.lang.Thread.run(Thread.java:923) 
2021-01-07 15:10:15.348 22070-22099/com.example.test_09 I/Process: Sending signal. PID: 22070 SIG: 9
 
Darius Boteand
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this can help as well, I do have confirmation that the issue is related with the database connection:
I did not include the class.forname(com.blablabla) and have had an actual output on my phone with the error as i had a textView that would display it on the phone. The error was saying that there was no suitable libraries found for the connection.
But as soon as I have added the line and ran the program, the app would crash straight away once i had press the load button...
 
Darius Boteand
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried to follow another tutorial, but I just have the same issue! As soon as I insert the jdbc driver, it just crashes! link
I really don't understand why my android studio doesn't want to use the jdbc driver...
 
Saloon Keeper
Posts: 6795
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On which Android API version are you running this? The code in question does something with lambdas, and that's supported only in Android versions 8 or newer (Android Oreo).

Also: Android supports JDBC 4.1, so be sure to use the Connector/J 5.1 driver, not the newer Connector/J 8, which is built on top of JDBC 4.2.

Lastly: Android apps should not use JDBC at all. If you need storage on the device, use the Room library. if you need to store something remotely, create a web service as a proxy to the database.
 
Darius Boteand
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for you answer! You see I have been using the latest driver, I didn't know that I wasn't meant to use other than the 5.1 version! this did solve my issue. Thank you very much!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic