欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SQL Server连接与关闭

程序员文章站 2024-02-22 23:01:34
...

SQLServer的基本应用

fun main() {
    //val df = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    val connection = DriverManager.getConnection(
        "jdbc:sqlserver://47.96.113.52:1433;databaseName=AIS20180930224051;",
        "sa", "ypbwkfyjhyhgzj_sql2018"
    )
    val stt="SCBL00000799"
    var str="select TOP 1 * from  t_material_receiving where 单据编号 = '" + stt+"'"
    val ps = connection.prepareStatement(str)
    val rs = ps.executeQuery()
    while (rs.next()) {
        println(rs.getString("单据"))
        println(rs.getString("单据编号"))
    }
    //一定记得关闭
    rs.close()
    ps.close()
    connection.close()
}