Commit e0b3af31 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti
Browse files

web: Add a method to check if a macaddr belongs to a school

parent 806a4ff6
......@@ -138,4 +138,31 @@ public class School implements java.io.Serializable {
return school;
}
public static boolean checkMachineBelongsToSchool(String inep, String macaddr) throws SQLException {
Connection conn = DB.getConnection();
boolean found = false;
try {
PreparedStatement st = conn.prepareStatement(
"SELECT 1 FROM dim_school sch, dim_inventory inv " +
"WHERE inv.sch_id=sch.id AND sch.inep=? and inv.macaddr=? " +
"GROUP BY inv.macaddr;");
st.setString(1, inep);
org.postgresql.util.PGobject macaddrobj = new org.postgresql.util.PGobject();
macaddrobj.setType("macaddr");
macaddrobj.setValue(macaddr);
st.setObject(2, macaddrobj);
ResultSet res = st.executeQuery();
if (res.next())
found = true;
}
finally {
conn.close();
}
return found;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment