mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 09:54:11 +00:00
27 lines
777 B
Plaintext
27 lines
777 B
Plaintext
|
contract PostgreSQLSample{
|
||
|
function onCreate(){
|
||
|
Global.dbArg= "jdbc:postgresql://127.0.0.1:5432/huaqiancai";
|
||
|
}
|
||
|
export function selectStudent(arg){
|
||
|
var conn = org.test.PostgreSQLUtil.connect(Global.dbArg);
|
||
|
if (conn!=undefined && !conn.isClosed()){
|
||
|
print("successfully connected");
|
||
|
}
|
||
|
else return "connect failed";
|
||
|
var sql = "select * from student;";
|
||
|
var statement = conn.createStatement();
|
||
|
var resultSet = statement.executeQuery(sql);
|
||
|
ret = [];
|
||
|
var meta = resultSet.getMetaData();
|
||
|
for (;resultSet.next();){
|
||
|
var line = {
|
||
|
};
|
||
|
for (var j=1;j<=meta.getColumnCount();j++){
|
||
|
line[meta.getColumnName(j)] = resultSet.getString(j);
|
||
|
}
|
||
|
ret.push(line);
|
||
|
}
|
||
|
return JSON.stringify(ret);
|
||
|
}
|
||
|
}
|