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

  • Scala for Data Science
  • Pascal Bugnion
  • 185字
  • 2021-07-23 14:33:10

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.

主站蜘蛛池模板: 马龙县| 鸡东县| 秭归县| 芒康县| 正阳县| 左云县| 辽宁省| 阿鲁科尔沁旗| 自治县| 杭锦旗| 静海县| 怀来县| 噶尔县| 宜昌市| 黄浦区| 大丰市| 房产| 云南省| 榆社县| 文山县| 确山县| 文安县| 威信县| 霍林郭勒市| 香河县| 柘城县| 丰镇市| 邓州市| 和静县| 青神县| 固阳县| 兴国县| 麻城市| 白水县| 皋兰县| 阳泉市| 鞍山市| 大余县| 岳阳县| 湄潭县| 革吉县|