官术网_书友最值得收藏!

JDBC summary

We now have an overview of JDBC. The rest of this chapter will concentrate on writing abstractions that sit above JDBC, making database accesses feel more natural. Before we do this, let's summarize what we have seen so far.

We have used three JDBC classes:

  • The Connection class represents a connection to a specific SQL database. Instantiate a connection as follows:
    import java.sql._
    Class.forName("com.mysql.jdbc.Driver")val connection = DriverManager.getConnection(
      "jdbc:mysql://127.0.0.1:3306/test",
      "root", // username when connecting
      "" // password
    )

    Our main use of Connection instances has been to generate PreparedStatement objects:

    connection.prepareStatement("SELECT * FROM physicists")
  • A PreparedStatement instance represents a SQL statement about to be sent to the database. It also represents the template for a SQL statement with placeholders for values yet to be filled in. The class exposes the following methods:
  • A ResultSet instance represents a set of rows returned by a SELECT or SHOW statement. ResultSet exposes methods to access fields in the current row:

The ResultSet instance exposes the .next method to move to the next row; .next returns true until the ResultSet has advanced to just beyond the last row.

主站蜘蛛池模板: 太和县| 玛纳斯县| 玉环县| 额济纳旗| 木里| 青州市| 客服| 福贡县| 准格尔旗| 调兵山市| 成武县| 峨眉山市| 黔东| 东丰县| 望谟县| 清原| 屏东市| 安多县| 玉树县| 大港区| 吴忠市| 黄大仙区| 砀山县| 奉贤区| 济阳县| 杭州市| 环江| 东源县| 昌邑市| 井陉县| 菏泽市| 革吉县| 延寿县| 乐昌市| 台安县| 阿克苏市| 应城市| 南江县| 诸城市| 云和县| 青铜峡市|