# kscript/kotlin 连接 mysql

kscript/kotlin 连接 mysql!

kscript '
//DEPS mysql:mysql-connector-java:8.0.16
 import java.util.Properties;
import java.sql.*;
import java.sql.Connection;



val connectionProps = Properties()
connectionProps.put("user", "root")
connectionProps.put("password", "root")
try {
    Class.forName("com.mysql.cj.jdbc.Driver")//.newInstance()
    val conn: Connection = DriverManager.getConnection(
            "jdbc:" + "mysql" + "://" +
                    "127.0.0.1" +
                    ":" + "3306" + "/" +
                    "test",
            connectionProps)
    var stmt = conn!!.createStatement()

    var rs = stmt.executeQuery("show tables")

    while(rs.next()){

        println(rs.getString("Tables_in_test"))
    }
            
} catch (ex: SQLException) {
    // handle any errors
    ex.printStackTrace()
} catch (ex: Exception) {
    // handle any errors
    ex.printStackTrace()
}
'

你可能感兴趣的:(# kscript/kotlin 连接 mysql)