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

  • 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.

主站蜘蛛池模板: 曲松县| 余干县| 班戈县| 金溪县| 易门县| 莫力| 阳高县| 舒兰市| 尤溪县| 东海县| 深水埗区| 苗栗县| 浑源县| 临沧市| 金沙县| 日喀则市| 桂阳县| 宣化县| 札达县| 大关县| 灌云县| 石城县| 邵阳县| 宁河县| 甘南县| 祁阳县| 怀来县| 宁海县| 黑龙江省| 乐陵市| 揭东县| 平江县| 广德县| 微博| 谢通门县| 海宁市| 凤庆县| 清镇市| 湘潭县| 前郭尔| 黄浦区|