泛微连接其他数据源
/获取数据源的信息。//和数据源取得连接。out.write("人数:" +counthrm);//关闭statement。
·
1.在后台配置好需要连接的数据源
2.代码
public Connection getConnection(String datasourceid) {
Connection conn = null;
try {
weaver.interfaces.datasource.DataSource datasource = (weaver.interfaces.datasource.DataSource) StaticObj.getServiceByFullname(datasourceid, weaver.interfaces.datasource.DataSource.class); //获取数据源的信息
conn = datasource.getConnection(); //和数据源取得连接
} catch (Exception e) {
}
return conn;
}
public void closeConnection(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
}
}
}
Connection conn = getConnection("datasource.testoa"); datasource.+数据源名
PreparedStatement s = conn.prepareStatement("select count(*) as counthrm from hrmresource");
ResultSet rs = s.executeQuery();
if (rs.next()) {
String counthrm = rs.getString("counthrm");
//输出到控制台
out.write("人数:" +counthrm);
}
rs.close();//关闭记录集
s.close();//关闭statement
//批量处理
RecordSet rs = new RecordSet();
String sql = " insert into uf_materialInfo(name) values(?)";
List<List> updateParList = new ArrayList<>();
for(int i =0;i<10;i++)
{
List<Object> list = new ArrayList<>();
list.add(i);
updateParList.add(list);
}
rs.executeBatchSql(sql,updateParList);

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)