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

Functional wrappers for JDBC

We now have a basic overview of the tools afforded by JDBC. All the objects that we have interacted with so far feel somewhat clunky and out of place in Scala. They do not encourage a functional style of programming.

Of course, elegance is not necessarily a goal in itself (or, at least, you will probably struggle to convince your CEO that he should delay the launch of a product because the code lacks elegance). However, it is usually a symptom: either the code is not extensible or too tightly coupled, or it is easy to introduce bugs. The latter is particularly the case for JDBC. Forgot to check wasNull? That will come back to bite you. Forgot to close your connections? You'll get an "out of memory exception" (hopefully not in production).

In the next sections, we will look at patterns that we can use to wrap JDBC types in order to mitigate many of these risks. The patterns that we introduce here are used very commonly in Scala libraries and applications. Thus, besides writing robust classes to interact with JDBC, learning about these patterns will, I hope, give you greater understanding of Scala programming.

主站蜘蛛池模板: 资阳市| 灵寿县| 黄陵县| 岳西县| 天长市| 霍州市| 静乐县| 顺平县| 察哈| 南陵县| 西丰县| 镇坪县| 集贤县| 平顺县| 望城县| 彰武县| 团风县| 南部县| 鄱阳县| 安龙县| 和静县| 瑞昌市| 长沙市| 汨罗市| 达拉特旗| 梅河口市| 沙坪坝区| 广元市| 肥乡县| 岳阳市| 永嘉县| 景洪市| 木兰县| 洛南县| 仙游县| 尚志市| 道孚县| 莫力| 察隅县| 伊吾县| 屯留县|