码迷,mamicode.com
首页 > 其他好文 > 详细

回调函数

时间:2016-02-19 12:30:48      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

1、海南室分项目里用的比较多的 js回调函数  callback  查看 积累 文件

2、定义:

import java.sql.{ResultSet, DriverManager}

import com.dtgroup.sparkmr.configuration.DBConnection

/**
* The package path is com.dtgroup.sparkmr.dao.
* Created by tommy duan on 2016/1/4.
*/
class SQLExecute private {
def executeQuery(sql:String,callback:ResultSetCallback):Unit = {
Class.forName(DBConnection.driver)
val connection = DriverManager.getConnection(DBConnection.url, DBConnection.username, DBConnection.password)
val statement = connection.createStatement()
val resultSet = statement.executeQuery(sql)
if (callback != null) {
callback.call(resultSet);
}
resultSet.close()
statement.close()
connection.close()
}
}
定义ResultSetCallback的接口
import java.sql.ResultSet

/**
* The package path is com.dtgroup.sparkmr.dao.
* Created by tommy duan on 2016/1/7.
*/
class ResultSetCallback {
def call(resultSet:ResultSet):Unit={}
}
调用:
SQLExecute.executeQuery("select distinct CellOID, NeighborCellOID from Tuning.Res_NeighborCell order by CellOID", new ResultSetCallback {
override def call(resultSet: ResultSet) = {
if (!resultSet.wasNull()) {
while (resultSet.next()) {
val cellId = resultSet.getInt("CellOID")
val neighborCellOID = resultSet.getInt("NeighborCellOID")
if (!neighborCellMap.contains(cellId)) {
neighborCellMap += (cellId -> List(neighborCellOID))
}
else {
neighborCellMap(cellId).::(neighborCellOID)
}
}
}
}
})

回调函数

标签:

原文地址:http://www.cnblogs.com/xiaomuchong/p/5200308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!