美文网首页工作生活
# kscript/kotlin 连接 mysql

# kscript/kotlin 连接 mysql

作者: 95d48fb8d89d | 来源:发表于2019-07-03 06:01 被阅读0次

    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

        本文链接:https://www.haomeiwen.com/subject/dmlfhctx.html