I press the button, and nothing happens, please help me. When you click on the button, the text in the TextView should change, but this does not happen. I added jtds to the libs folder and Project structure did everything.
package com.example.db;
import android.os.StrictMode;
import android.util.Log;
import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionHelper {
Connection con;
String database, ip, port;
public Connection ConnectionClass()
{
database = "android";
ip = "192.168.56.1";
port = "1433";
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String ConnectionURL = null;
try{
Class.forName("net.sourceforge.jtbs.jdbc.Driver");
ConnectionURL = "jdbc.jdbc:sqlserver://"+ip+":"+port+";"+"databasename="+database+";";
connection = DriverManager.getConnection(ConnectionURL);
}
catch (Exception ex){
Log.e("Error", ex.getMessage());
}
return connection;
}
}
MainActivity:
package com.example.db;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class MainActivity extends AppCompatActivity {
Connection connect;
String ConnectionResult = "";
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void GetTextFromSQL(View v)
{
TextView tx1 = (TextView) findViewById(R.id.tx1);
try{
ConnectionHelper connectionHelper = new ConnectionHelper();
connect = connectionHelper.ConnectionClass();
if(connect!=null)
{
String query = "Select * from Tabble";
Statement st = connect.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
tx1.setText(rs.getString(1));
}
}
else{
ConnectionResult="Check connection";
}
}
catch (Exception ex)
{
}
}
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.db">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DB">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In the run tab:
04/30 00:01:35: Launching 'app' on Pixel_3a_API_30_x86.
Install successfully finished in 1 s 191 ms.
$ adb shell am start -n "com.example.db/com.example.db.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 21688 on device 'emulator-5554'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/com.example.db: Not late-enabling -Xcheck:jni (already on)
I/com.example.db: Unquickening 12 vdex files!
W/com.example.db: Unexpected CPU variant for X86 using defaults: x86
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
W/com.example.db: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/HostConnection: HostConnection::get() New Host Connection established 0xf21f4ce0, tid 21716
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_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xf21f57d0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xf21f57d0: ver 2 0 (tinfo 0xf25381d0) (first time)
I/Gralloc4: mapper 4.x is not supported
D/HostConnection: createUnique: call
HostConnection::get() New Host Connection established 0xf21f5530, tid 21716
D/goldfish-address-space: allocate: Ask for block of size 0x100
D/goldfish-address-space: allocate: ioctl allocate returned offset 0x3fb93f000 size 0x2000
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_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2
I/Choreographer: Skipped 47 frames! The application may be doing too much work on its main thread.
I/OpenGLRenderer: Davey! duration=858ms; Flags=0, IntendedVsync=7931727961529, Vsync=7932511294831, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=7932517765000, AnimationStart=7932517808800, PerformTraversalsStart=7932518757100, DrawStart=7932524318700, SyncQueued=7932526467100, SyncStart=7932527472800, IssueDrawCommandsStart=7932527780500, SwapBuffers=7932535240400, FrameCompleted=7932587097200, DequeueBufferDuration=198900, QueueBufferDuration=9719100, GpuCompleted=-7596402803422855178,
I/com.example.db: Background young concurrent copying GC freed 37944(2476KB) AllocSpace objects, 1(20KB) LOS objects, 91% free, 2340KB/26MB, paused 632us total 888.550ms
E/Error: net.sourceforge.jtbs.jdbc.Driver