首页 > 数据库技术 > 详细

jdbc执行Statement接口的步骤

时间:2016-10-30 13:33:54      阅读:271      评论:0      收藏:0      [点我收藏+]

   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接口的步骤

原文:http://www.cnblogs.com/LZL-student/p/6012739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!