This is the first piece of code and execution result in the following:
The import kotlin. Concurrent. Thread
Fun main () {
ZhusuInOut1 ()
}
Private fun zhusuInOut1 () {
Val queryInList1=ArrayList()
Try {
Thread {
Val conn=DBUtil (.) conection ()
Try {
Val sql1="SELECT * FROM zhusuintable where name='75 g and color=' no '"
//create objects needed to execute SQL statements
//val statement: statement=conn!!!!! CreateStatement ()
Val preparedStatement=conn!!!!! . PrepareStatement (sql1)
//execute SQL query and retrieve the query information
//val rSet1: the ResultSet=statement. The executeQuery (sql1)
Val resultSet=preparedStatement. ExecuteQuery ()
Println (" query ")
While (resultSet. Next ()) {
Shuliang val tile1=the resultSet. Get string (" ")
QueryInList1. Add (tile1)
Println (" query data to set successful ")
For (I in queryInList1) {
Println (I)
}
}
{} the catch (e: Exception)
E.p rintStackTrace ()
}
}
{} the catch (e: Exception)
E.p rintStackTrace ()
}
}
The first piece of code execution result is as follows:
Query success
Join query data collection success
5622
Join query data collection success
5622
2314
This is the second piece of code and execution result below:
The import android. OS. Bundle
The import android. Util. Log
The import kotlinx. Android. Synthetic. Main. Query_in_out_layout. *
The import kotlinx. Android. Synthetic. Main. Super_manager_layout. The toolbar
Import the Java. SQL. The ResultSet
Import the Java. SQL. SQLException
Import of Java, SQL Statement
The import kotlin. Concurrent. Thread
The class TestInOut: BaseActivity () {
Override fun onCreate (savedInstanceState: Bundle? {
Super. OnCreate (savedInstanceState)
The setContentView (R.l ayout. Test_in_out)
SetSupportActionBar (toolbar)
Thread {
TestQueryBtm. SetOnClickListener {
Try {
Thread {
Val conn=DBUtil (.) conection ()
Try {
Val queryInList1=ArrayList()
Val sql1="SELECT * FROM zhusuintable where name='75 g and color=' no '"
//create objects needed to execute SQL statements
Val statement: statement=conn!!!!! CreateStatement ()
//val preparedStatement=conn!!!!! . PrepareStatement (sql1)
//execute SQL query and retrieve the query information
Val rSet1: the ResultSet=statement. ExecuteQuery (sql1)
//val resultSet=preparedStatement. ExecuteQuery ()
Println (" query ")
While (rSet1. Next ()) {
Shuliang val find1=rSet1. Get string (" ")
QueryInList1. Add (find1)
Println (" query data to set successful ")
}
{} the catch (e: Exception)
E.p rintStackTrace ()
}
Try {
Conn!!!!! The close ()
The d (" QueryInOut ", "close the database connection is successful,")
{} the catch (e: SQLException)
The d (" QueryInOut ", "close the connection fails,")
}
}
{} the catch (e: Exception)
E.p rintStackTrace ()
}
}
}
}
Private fun test11 () {
}
}
If the above code execution is as follows:
D/BaseActivity: TestInOut
I/System. Out: query success
D/QueryInOut: close the database connection is successful,