方法一
String sql="SELECT parentEquipmentId` FROM xy_measuringpoint_list group by parentEquipmentId`";
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/znkk","root","root");
Statement stmt=conn.createStatement();
conn.setAutoCommit(false);//更改jdbc事务的默认提交方式
ResultSet resultSet=stmt.executeQuery(sql);得到结果集
conn.commit();//提交
conn.setAutoCommit(true);
List<String> deviceIds=new ArrayList<>();
while (resultSet.next()){
deviceIds.add(resultSet.getString(1));
}
方法二
在xml文件编辑
<select id="findDeviceId" resultType="java.lang.String">
select parentEquipmentId from xy_measuringpoint_list
</select>
dao
List<String> findDeviceId();
service
List<String> findDeviceId();
serviceImpl
@Override
public List<String> findDeviceId() {
List<String> deviceIds= xyMeasuringpointListDao.findDeviceId();
return deviceIds;
}
使用(Impl)
List<String> deviceIds=measuringpointListService.findDeviceId();