zoukankan      html  css  js  c++  java
  • jdbc连接数据库的步骤

    网传已久的:贾琏欲执事,即:加载驱动,建立连接,创建语句,执行语句,释放资源

    1、加载驱动

    class.forName("com.mysql.jdbc.Driver");

    2、建立连接

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

    3、创建语句

    PreparedStatement ps = conn.prepareStatement("select * from employee where id  = ?");

    ps.setInt(5);

    4、执行语句

    //执行SQL语句,查询。返回ResultSet对象(结果集)

    Result rs = ps.executeQuery();

    //executeUpdate(sql);
    // 执行DDL/DML语句,执行DML返回受影响的行数,DDL返回0

    5、释放资源

    finally{

      if(conn!=null){

        conn.close();

      }

    }

  • 相关阅读:
    B
    A
    P1057 传球游戏
    P1702 突击考试
    P1394 山上的国度
    P2117 小Z的矩阵
    P1510 精卫填海
    P1294 高手去散步
    P1071 潜伏者
    保留
  • 原文地址:https://www.cnblogs.com/xiaoxli/p/9453051.html
Copyright © 2011-2022 走看看