• jdbc执行Statement接口的步骤


       jdbc执行Statement接口的步骤如下:

        1)驱动注册程序:

    Class.forName(com.mysql.jdbc.Driver);

        2)获取连接对象: 

    Connection conn = DriverManager.getConnection(url,user,password);

        3)创建Statement对象:

     Statement stsm = conn.createStatement();

        4)准备sql语句:(静态的sql语句)

        5)执行sql语句:

    stsm.executeUpdate(sql);

        6)输出:

        7)关闭连接:

     1 if (stsm != null) {
     2             try {
     3                 stsm.close();
     4             } catch (SQLException e) {
     5                 // TODO Auto-generated catch block
     6                 e.printStackTrace();
     7                 throw new RuntimeException(e);
     8             }
     9         }
    10 
    11         if (conn != null) {
    12             try {
    13                 conn.close();
    14             } catch (SQLException e) {
    15                 // TODO Auto-generated catch block
    16                 e.printStackTrace();
    17                 throw new RuntimeException(e);
    18             }
    19         }

      

  • 相关阅读:
    FileAttributes枚举
    File类与FileInfo类
    System.IO.Path类
    会话状态Session
    Application共享数据
    压缩、解压缩流GZipStream
    MemoryStream类
    FileMode枚举
    FileAccess枚举
    MySQL函数
  • 原文地址:https://www.cnblogs.com/LZL-student/p/6012739.html
Copyright © 2020-2023  润新知