public void validatePsqlReelDataQuantity() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
String text = data.get(dataKey);
System.out.println("input " + text);
test.log(Status.INFO, "Executing: "+text);
Class.forName("org.postgresql.ds.PGSimpleDataSource").newInstance();
Connection con=DriverManager.getConnection("jdbc:postgresql://192.168.4.23:5432/PanaCIM?user=cim&password=cim");
Statement stmt=con.createStatement();
try {
ResultSet rs=stmt.executeQuery(text);
while(rs.next()) {
int number = rs.getInt("count");
System.out.println(number);
if(number == 1) {
System.out.println("material only appear once");
test.log(Status.PASS, "material only appear once");
}else {
System.out.println("material appear " + number + " times");
test.log(Status.FAIL, "material appear " + number + " times");
}
}
}catch(SQLException e) {
e.printStackTrace();
// System.out.println("material don't exist");
// test.log(Status.FAIL, "material don't exist");
}
try {
stmt.close();
}catch(SQLException e) {
e.printStackTrace();
}
try {
con.close();
}catch (SQLException e) {
e.printStackTrace();
}
}
数据库查询数据出现次数
于 2019-11-06 12:00:32 首次发布