验证数据库中某条数据的某个值是否存在

public void validatePsqlReelDataElement () throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, InterruptedException {
    
    
//		try {
    
    
		Thread.sleep(5000);
		String text = data.get(dataKey);
		String[] str = text.split(";");
		String expression = str[0];
		String amount = str[1];
		System.out.println("input " + text);
//		String str[] = text.split(";");
//		String sql = str[0];
		test.log(Status.INFO, "Executing: "+expression);
		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();
		ResultSet rs=stmt.executeQuery(expression);
//		String columnName = str[1];
		while(rs.next()) {
    
    
			int quantity = rs.getInt("quantity");
			int number = Integer.parseInt(amount);
			if(quantity==number) {
    
    
//			int count = ResultSet.getInt("count");
			System.out.println("material exist");
			test.log(Status.PASS, "material exist");
		}
		else {
    
    
//		} catch(Exception e) {
    
    
//			e.printStackTrace();
			test.log(Status.FAIL, "material don't exist");
		}
		}
//		}
	}

猜你喜欢

转载自blog.csdn.net/weixin_43487218/article/details/102932595