Code example for PreparedStatement

Methods: executeUpdatesetIntsetStringgetGeneratedKeys

0
		String sql =
		             "INSERT INTO UM_PERMISSION (UM_RESOURCE_ID, UM_MODULE_ID, UM_TENANT_ID, UM_ACTION) VALUES(?,?,?,?) "; 
 
		stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
		byte count = 0;
		stmt.setString(++count, getResourceId());
		stmt.setInt(++count, getModuleId());
		stmt.setInt(++count, getTenantId());
		stmt.setString(++count, getAction());
 
		int resCount = stmt.executeUpdate();
		if (resCount == 0) {
			String error = "Insertion faild for the permission";
			log.error(error);
			throw new UserStoreException(error);
		} 
		res = stmt.getGeneratedKeys();
		if (res.next()) {
			setPermissionId(res.getInt(1));
		} 
 
	} 
Stop searching for code, let great code find you!  Add Codota to your java IDE