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

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.

主站蜘蛛池模板: 兴城市| 镇原县| 临猗县| 固镇县| 肥东县| 苏州市| 浙江省| 滕州市| 洞口县| 津市市| 汪清县| 台南县| 和田县| 郧西县| 济阳县| 五台县| 上栗县| 江达县| 蒙山县| 彭泽县| 淳安县| 溆浦县| 山东| 青阳县| 永州市| 河津市| 拜泉县| 垣曲县| 绥德县| 井陉县| 辉县市| 色达县| 衢州市| 湘乡市| 微博| 东方市| 元阳县| 元氏县| 清河县| 苏尼特右旗| 舞钢市|