Home > Mobile >  0 basis for help to connect the mysql
0 basis for help to connect the mysql

Time:11-19

I'm a fan a 0 based program, in a recent study in the following questions, the great god to see where the problem is, please, here is my main code, after trial operation error, error content behind:
 package com. Example. Datatest 

The import android. OS. Bundle
The import android. Util. Log
The import androidx. Appcompat. App. AppCompatActivity
Import the Java. SQL. *
Import the Java. SQL. DriverManager;


The class MainActivity: AppCompatActivity () {
Override fun onCreate (savedInstanceState: Bundle? {
Super. OnCreate (savedInstanceState)
The setContentView (R.l ayout. Activity_main)


//load database driven

//load database driven
Try {
Class.forname (". Com. Mysql. Cj. JDBC Driver ")
The d (" MainActivity ", "load the JDBC driver success!" )
{} the catch (e: a ClassNotFoundException)
The d (" MainActivity ", "load the JDBC driver failed!" )
Return
}
//connect to the database (open up a new thread)
//connect to the database (open up a new thread)
Val thread=thread (Runnable {
//try to connect again and again, until the connection is successful after exit loop
While (! Thread. Interrupted ()) {
Try {
Thread.sleep (100)//every 0.1 seconds to try to connect
{} the catch (e: InterruptedException)
The e (" MainActivity ", e. oString ())
}

//2. Set the IP/port/database name/user name/password necessary connection information such as
//val IP="192.168.1.10"//native IP
//val port=3307//mysql default port
//val dbName="test1"//your database name
Val url="JDBC: mysql://192.168.1.10:3307/test1? UseSSL=false& ServerTimezone=UTC& ServerTimezone=GMT % 2 b8 "
/mysql/build connection string
Val user="QDCKSJ"//your own user name
Val password="87426619"//their passwords

//3. JDBC connection
Try {
Val conn=DriverManager. GetConnection (url, user, password)
The d (" MainActivity ", "connect to the database success!" )
//query students table
Val SQL="SELECT * FROM table1"
Try {
//create objects needed to execute SQL statements
Val statement: statement=conn. CreateStatement ()
//execute SQL query and retrieve the query information
Val rSet: the ResultSet=statement. ExecuteQuery (SQL)
//iteration to print out the query information
The d (" MainActivity ", "student list")
The d (" MainActivity ", "id \ t \ \ t tname \ tage \ tsex \ t")
While (rSet), next ()) {
The d (" MainActivity ", rSet. Get string (" id "). The toString () + "\ t" + rSet. Get string (" name ") + "\ t"
+ rSet. Get string (" age ") + "\ t" + rSet. Get string (" sex ") + "\ t")
}
{} the catch (e: SQLException)
The e (" MainActivity ", "query error")
}
//close the database
Try {
Conn. Close ()
The d (" MainActivity ", "close the connection is successful,")
{} the catch (e: SQLException)
The d (" MainActivity ", "close the connection fails,")
}
Return the @ Runnable
{} the catch (e: SQLException)
The d (" MainActivity ", "connect to database failure!" )
}
}
})
Thread. The start ()

}
}


Below is the error content:
 
The 2020-11-17 17:27:48. 509, 25733-25833/com. Example. Datatest E/AndroidRuntime: FATAL EXCEPTION: Thread - 2
Process: com. Example. Datatest, PID: 25733
Java. Lang. NoClassDefFoundError: Failed resolution of: Ljavax/security/sasl/SaslClientFactory;
At com. Mysql. Cj. Protocol. A.a uthentication. AuthenticationLdapSaslClientPlugin. & lt; clinit> (AuthenticationLdapSaslClientPlugin. Java: 59)
At com. Mysql. Cj. Protocol. A.N ativeAuthenticationProvider. LoadAuthenticationPlugins (NativeAuthenticationProvider. Java: 246)
At com. Mysql. Cj. Protocol. A.N ativeAuthenticationProvider. ProceedHandshakeWithPluggableAuthentication (NativeAuthenticationProvider. Java: 387)
At com. Mysql. Cj. Protocol. A.N ativeAuthenticationProvider. Connect (NativeAuthenticationProvider. Java: 174)
At com. Mysql. Cj. Protocol. A.N ativeProtocol. Connect (NativeProtocol. Java: 1348)
At com. Mysql. Cj. NativeSession. Connect (NativeSession. Java: 157)
At com. Mysql. Cj. JDBC. ConnectionImpl. ConnectOneTryOnly (ConnectionImpl. Java: 956)
At com. Mysql. Cj. JDBC. ConnectionImpl. CreateNewIO (ConnectionImpl. Java: 826)
At com. Mysql. Cj. JDBC. ConnectionImpl. & lt; init> (ConnectionImpl. Java: 456)
At com. Mysql. Cj. JDBC. ConnectionImpl. GetInstance (ConnectionImpl. Java: 246)
At com. Mysql. Cj. JDBC. NonRegisteringDriver. Connect (NonRegisteringDriver. Java: 198)
The at Java. SQL. DriverManager. GetConnection (DriverManager. Java: 580)
The at Java. SQL. DriverManager. GetConnection (DriverManager. Java: 218)
At com. Example. Datatest. MainActivity $$thread onCreate $1. The run (MainActivity. Kt: 49)
The at Java. Lang. Thread. The run (Thread. Java: 923)
Under Caused by: Java. Lang. ClassNotFoundException: Didn 't find the class "javax.mail. Security. Sasl. SaslClientFactory" on the path: DexPathList [[zip file "/data/app/~ ~ pA69XhKMRrYXxYgrbSjaPw==/com. The example. The datatest - 8 ijwktdzj437lqhgqduuzg==/base. The apk"], nativeLibraryDirectories=[/data/app/~ ~ pA69XhKMRrYXxYgrbSjaPw==/com. The example. The datatest - 8 ijwktdzj437lqhgqduuzg==/lib/x86,/system/lib/system_ext/lib/product/lib]]
The at dalvik. System. BaseDexClassLoader. FindClass (BaseDexClassLoader. Java: 207)
The at Java. Lang. This. LoadClass (379). This Java:
The at Java. Lang. This. LoadClass (312). This Java:
At com. Mysql. Cj. Protocol. A.a uthentication. AuthenticationLdapSaslClientPlugin. & lt; clinit> (AuthenticationLdapSaslClientPlugin. Java: 59)
At com. Mysql. Cj. Protocol. A.N ativeAuthenticationProvider. LoadAuthenticationPlugins (NativeAuthenticationProvider. Java: 246)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related