3.1 連接數(shù)據(jù)庫(kù)
@Keyword
def connectDBcatc(){
//Load driver class for your specific database type
//String conn = "jdbc:oracle:thin:@" + host + ":" + port + ":" + sid
String conn = "jdbc:oracle:thin:@111.11.111.11:1111:orcl"
String usernameofcata = "PIM_PICL_CATC"
String passwordofcata = "PIM_PICL_CATC"
if(connection != null && !connection.isClosed()){
connection.close()
}
connection = DriverManager.getConnection(conn, usernameofcata, passwordofcata)
return connection
}
3.2 執(zhí)行SQL 語(yǔ)句
/**
* execute a SQL query on database
* @param queryString SQL query string
* @return a reference to returned data collection, an instance of java.sql.ResultSet
*/
//Executing the constructed Query and Saving results in resultset
@Keyword
def executeQuery(String queryString) {
Statement stm = connection.createStatement()
ResultSet rs = stm.executeQuery(queryString)
return rs
}
3.3 關(guān)閉連接
//Closing the connection
@Keyword
def closeDatabaseConnection() {
if(connection != null && !connection.isClosed()){
connection.close()
}
connection = null
}