首页 > 代码库 > jdbc执行Statement接口的步骤

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         }

 

  

jdbc执行Statement接口的步骤